0.10.0 add peewee.SnowflakeField()

This commit is contained in:
Yusur 2025-11-23 19:13:14 +01:00
parent def2634f21
commit 5c9a6f2c7e
3 changed files with 29 additions and 4 deletions

View file

@ -1,5 +1,9 @@
# Changelog
## 0.10.0
+ `peewee`: add `SnowflakeField` class
## 0.9.0
+ Fix to make experimental `Waiter` usable

View file

@ -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',

View file

@ -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')