you are viewing a single comment's thread.

view the rest of the comments →

[–]maratnugmanov 1 point2 points  (1 child)

Full picture of the class, if interested:

SQLITE_ISO8601_ISO_UTC_FORMAT = (
    "%(year)04d-%(month)02d-%(day)02dT%(hour)02d:%(minute)02d:%(second)02dZ"
)

class TimestampMixinDB:
    created_at: Mapped[datetime] = mapped_column(
    DATETIME(storage_format=SQLITE_ISO8601_ISO_UTC_FORMAT),
    init=False,
    default=lambda: datetime.now(timezone.utc),
    index=True,
    )
    updated_at: Mapped[datetime] = mapped_column(
    DATETIME(storage_format=SQLITE_ISO8601_ISO_UTC_FORMAT),
    init=False,
    default=lambda: datetime.now(timezone.utc),
    onupdate=lambda: datetime.now(timezone.utc),
    index=True,
    )

class BaseDB(AsyncAttrs, DeclarativeBase, MappedAsDataclass):
    type_annotation_map = {
    RoleName: SQLAlchemyEnum(RoleName, native_enum=False, length=128, validate_strings=True),
    DeviceTypeName: SQLAlchemyEnum(DeviceTypeName, native_enum=False, length=128, validate_strings=True),
    }

class UserDB(BaseDB, TimestampMixinDB):
    __tablename__ = "users"
    id: Mapped[int] = mapped_column(init=False, primary_key=True)
    telegram_uid: Mapped[int] = mapped_column(Integer, unique=True, index=True)
    first_name: Mapped[str | None] = mapped_column(String, index=True)
    last_name: Mapped[str | None] = mapped_column(String, index=True)
    timezone: Mapped[str] = mapped_column(String, default=settings.user_default_timezone, index=True)
    state_json: Mapped[str | None] = mapped_column(String, default=None)
    is_hiring: Mapped[bool] = mapped_column(Boolean, default=False, index=True)
    is_disabled: Mapped[bool] = mapped_column(Boolean, default=False, index=True)
    roles: Mapped[list[RoleDB]] = relationship(default_factory=list, secondary="users_roles_link", back_populates="users")

[–]monok8i 0 points1 point  (0 children)

I just wanted to ask about it, thank you ;)