orm
Application ORM configuration.
DTO_KEY
module-attribute
¶
The key we use to reference dto.DTOField
in the SQLAlchemy info dict.
convention
module-attribute
¶
convention = {
"ix": "ix_%(column_0_label)s",
"uq": "uq_%(table_name)s_%(column_0_name)s",
"ck": "ck_%(table_name)s_%(constraint_name)s",
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
"pk": "pk_%(table_name)s",
}
Templates for automated constraint name generation.
Base ¶
Bases: DeclarativeBase
Base for all SQLAlchemy declarative models.
created
class-attribute
¶
created: Mapped[datetime] = mapped_column(
default=datetime.now, info={DTO_KEY: dto.DTOField(mark=dto.Mark.READ_ONLY)}
)
Date/time of instance creation.
id
class-attribute
¶
id: Mapped[UUID] = mapped_column(
default=uuid4, primary_key=True, info={DTO_KEY: dto.DTOField(mark=dto.Mark.READ_ONLY)}
)
Primary key column.
updated
class-attribute
¶
updated: Mapped[datetime] = mapped_column(
default=datetime.now, info={DTO_KEY: dto.DTOField(mark=dto.Mark.READ_ONLY)}
)
Date/time of instance update.
touch_updated_timestamp ¶
Set timestamp on update.
Called from SQLAlchemy's
before_flush
event to bump the updated
timestamp on modified instances.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
Session
|
The sync |
required |