fix(db): Add __repr__ to custom column types, same as done by SQLAlchemy
This commit is contained in:
parent
e09d563e93
commit
bf02c0e21f
|
@ -1,7 +1,7 @@
|
||||||
import sys
|
import sys
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from sqlalchemy import BigInteger
|
from sqlalchemy import BigInteger, util
|
||||||
from sqlalchemy.dialects import mysql, sqlite
|
from sqlalchemy.dialects import mysql, sqlite
|
||||||
from sqlalchemy.types import DateTime, TypeDecorator
|
from sqlalchemy.types import DateTime, TypeDecorator
|
||||||
|
|
||||||
|
@ -50,6 +50,10 @@ class Serial(TypeDecorator):
|
||||||
cache_ok = True
|
cache_ok = True
|
||||||
impl = BigInteger().with_variant(mysql.BIGINT(unsigned=True), "mysql").with_variant(sqlite.INTEGER(), "sqlite")
|
impl = BigInteger().with_variant(mysql.BIGINT(unsigned=True), "mysql").with_variant(sqlite.INTEGER(), "sqlite")
|
||||||
|
|
||||||
|
# https://alembic.sqlalchemy.org/en/latest/autogenerate.html?highlight=custom%20column#affecting-the-rendering-of-types-themselves
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return util.generic_repr(self)
|
||||||
|
|
||||||
|
|
||||||
class UtcDateTime(TypeDecorator):
|
class UtcDateTime(TypeDecorator):
|
||||||
"""Almost equivalent to `sqlalchemy.types.DateTime` with
|
"""Almost equivalent to `sqlalchemy.types.DateTime` with
|
||||||
|
@ -85,3 +89,7 @@ class UtcDateTime(TypeDecorator):
|
||||||
value = value.astimezone(datetime.timezone.utc)
|
value = value.astimezone(datetime.timezone.utc)
|
||||||
value = value.replace(tzinfo=datetime.timezone.utc)
|
value = value.replace(tzinfo=datetime.timezone.utc)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
# https://alembic.sqlalchemy.org/en/latest/autogenerate.html?highlight=custom%20column#affecting-the-rendering-of-types-themselves
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return util.generic_repr(self)
|
||||||
|
|
Loading…
Reference in New Issue