0.10.0 add peewee.SnowflakeField()
This commit is contained in:
parent
def2634f21
commit
5c9a6f2c7e
3 changed files with 29 additions and 4 deletions
|
|
@ -1,5 +1,9 @@
|
|||
# Changelog
|
||||
|
||||
## 0.10.0
|
||||
|
||||
+ `peewee`: add `SnowflakeField` class
|
||||
|
||||
## 0.9.0
|
||||
|
||||
+ Fix to make experimental `Waiter` usable
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ from .redact import redact_url_password
|
|||
from .http import WantsContentType
|
||||
from .color import chalk, WebColor
|
||||
|
||||
__version__ = "0.9.0"
|
||||
__version__ = "0.10.0"
|
||||
|
||||
__all__ = (
|
||||
'ConfigOptions', 'ConfigParserConfigSource', 'ConfigSource', 'ConfigValue',
|
||||
|
|
|
|||
|
|
@ -18,10 +18,11 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
from contextvars import ContextVar
|
||||
from typing import Iterable
|
||||
from playhouse.shortcuts import ReconnectMixin
|
||||
from peewee import CharField, Database, MySQLDatabase, _ConnectionState
|
||||
from peewee import BigIntegerField, CharField, Database, MySQLDatabase, _ConnectionState
|
||||
import re
|
||||
|
||||
from suou.iding import Siq
|
||||
from suou.snowflake import Snowflake
|
||||
|
||||
from .codecs import StringCase
|
||||
|
||||
|
|
@ -117,6 +118,26 @@ class SiqField(Field):
|
|||
def python_value(self, value: bytes) -> Siq:
|
||||
return Siq.from_bytes(value)
|
||||
|
||||
# Optional dependency: do not import into __init__.py
|
||||
__all__ = ('connect_reconnect', 'RegexCharField', 'SiqField')
|
||||
|
||||
class SnowflakeField(BigIntegerField):
|
||||
'''
|
||||
Field holding a snowflake.
|
||||
|
||||
Stored as bigint.
|
||||
|
||||
XXX UNTESTED!
|
||||
'''
|
||||
field_type = 'bigint'
|
||||
|
||||
def db_value(self, value: int | Snowflake) -> int:
|
||||
if isinstance(value, Snowflake):
|
||||
value = int(value)
|
||||
if not isinstance(value, int):
|
||||
raise TypeError
|
||||
return value
|
||||
def python_value(self, value: int) -> Snowflake:
|
||||
return Snowflake(value)
|
||||
|
||||
# Optional dependency: do not import into __init__.py
|
||||
__all__ = ('connect_reconnect', 'RegexCharField', 'SiqField', 'Snowflake')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue