orm get dict and id columns mappers updated
This commit is contained in:
@@ -20,7 +20,7 @@ from sqlalchemy_mixins.serialize import SerializeMixin
|
||||
from sqlalchemy_mixins.repr import ReprMixin
|
||||
from sqlalchemy_mixins.smartquery import SmartQueryMixin
|
||||
|
||||
from api_library.date_time_actions.date_functions import DateTimeLocal
|
||||
from api_library.date_time_actions.date_functions import DateTimeLocal, client_arrow
|
||||
from api_objects.auth.token_objects import Credentials
|
||||
|
||||
from databases.sql_models.sql_operations import FilterAttributes
|
||||
@@ -133,19 +133,23 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
||||
@classmethod
|
||||
def iterate_over_variables(cls, val, key):
|
||||
key_ = cls.__annotations__.get(key, None)
|
||||
if val is None or key_ is None:
|
||||
is_primary, is_foreign_key = key in cls.primary_keys and bool(getattr(cls, key).foreign_keys)
|
||||
if is_primary or is_foreign_key and key_ == Mapped[int]:
|
||||
return None
|
||||
elif key_ == Mapped[Identity]:
|
||||
return None
|
||||
elif key_ == Mapped[bool]:
|
||||
return bool(val)
|
||||
elif key_ == Mapped[float] or key_ == Mapped[NUMERIC]:
|
||||
return float(val)
|
||||
elif key_ == Mapped[UUID]:
|
||||
return str(val) if val else None
|
||||
elif key_ == Mapped[int]:
|
||||
return int(val)
|
||||
return int(val) if val else None
|
||||
elif key_ == Mapped[bool]:
|
||||
return bool(val) if val else None
|
||||
elif key_ == Mapped[float] or key_ == Mapped[NUMERIC]:
|
||||
return float(val) if val else None
|
||||
elif key_ == Mapped[int]:
|
||||
return int(val) if val else None
|
||||
elif key_ == Mapped[TIMESTAMP]:
|
||||
return str(cls.client_arrow.get(val).format("DD-MM-YYYY HH:mm:ss"))
|
||||
return str(val)
|
||||
return str(client_arrow.get(val).format("DD-MM-YYYY HH:mm:ss")) if val else None
|
||||
return str(val) if val else None
|
||||
|
||||
|
||||
def update(self, **kwargs):
|
||||
"""Updates the record with the given attributes."""
|
||||
@@ -227,7 +231,7 @@ class BaseCollection(CrudMixin, BaseMixin):
|
||||
__abstract__ = True
|
||||
__repr__ = ReprMixin.__repr__
|
||||
|
||||
id: Mapped[Identity] = mapped_column(primary_key=True)
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
|
||||
|
||||
class CrudCollection(CrudMixin, BaseMixin, SmartQueryMixin):
|
||||
@@ -235,7 +239,7 @@ class CrudCollection(CrudMixin, BaseMixin, SmartQueryMixin):
|
||||
__abstract__ = True
|
||||
__repr__ = ReprMixin.__repr__
|
||||
|
||||
id: Mapped[Identity] = mapped_column(primary_key=True)
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
uu_id: Mapped[UUID] = mapped_column(
|
||||
UUID, server_default=func.text("gen_random_uuid()"), index=True, unique=True
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user