fixed bug in sqlalchemy.id_column()
This commit is contained in:
parent
e5d9c8e4a6
commit
3d03cc00fa
4 changed files with 8 additions and 5 deletions
|
|
@ -3,6 +3,7 @@
|
|||
## 0.3.3
|
||||
|
||||
- Fixed leftovers in `snowflake` module from unchecked code copying — i.e. `SnowflakeGen.generate_one()` used to require an unused typ= parameter
|
||||
- Fixed a bug in `id_column()` that made it fail to provide a working generator — again, this won't be backported
|
||||
|
||||
## 0.3.2
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ from .itertools import makelist, kwargs_prefix, ltuple, rtuple, additem
|
|||
from .i18n import I18n, JsonI18n, TomlI18n
|
||||
from .snowflake import Snowflake, SnowflakeGen
|
||||
|
||||
__version__ = "0.3.3.rc1"
|
||||
__version__ = "0.3.3"
|
||||
|
||||
__all__ = (
|
||||
'Siq', 'SiqCache', 'SiqType', 'SiqGen', 'StringCase',
|
||||
|
|
|
|||
|
|
@ -206,7 +206,9 @@ class SiqCache:
|
|||
return self.generator.last_gen_ts
|
||||
def cur_timestamp(self):
|
||||
return self.generator.cur_timestamp()
|
||||
def __init__(self, generator: SiqGen, typ: SiqType, size: int = 64, max_age: int = 1024):
|
||||
def __init__(self, generator: SiqGen | str, typ: SiqType, size: int = 64, max_age: int = 1024):
|
||||
if isinstance(generator, str):
|
||||
generator = SiqGen(generator)
|
||||
self.generator = generator
|
||||
self.typ = typ
|
||||
self.size = size
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ from .itertools import kwargs_prefix, makelist
|
|||
from .signing import HasSigner, UserSigner
|
||||
from .codecs import StringCase
|
||||
from .functools import deprecated, not_implemented
|
||||
from .iding import SiqType, SiqCache
|
||||
from .iding import Siq, SiqGen, SiqType, SiqCache
|
||||
from .classtools import Incomplete, Wanted
|
||||
|
||||
_T = TypeVar('_T')
|
||||
|
|
@ -67,9 +67,9 @@ def id_column(typ: SiqType, *, primary_key: bool = True, **kwargs):
|
|||
"""
|
||||
def new_id_factory(owner: DeclarativeBase) -> Callable:
|
||||
domain_name = owner.metadata.info['domain_name']
|
||||
idgen = SiqCache(domain_name, typ)
|
||||
idgen = SiqCache(SiqGen(domain_name), typ)
|
||||
def new_id() -> bytes:
|
||||
return idgen.generate().to_bytes()
|
||||
return Siq(idgen.generate()).to_bytes()
|
||||
return new_id
|
||||
if primary_key:
|
||||
return Incomplete(Column, IdType, primary_key = True, default = Wanted(new_id_factory), **kwargs)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue