orm
Application ORM configuration.
DTO_KEY
module-attribute
¶
The key we use to reference dto.Attrib 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.Attrib(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.Attrib(mark=dto.Mark.READ_ONLY)}
)
Primary key column.
updated
class-attribute
¶
updated: Mapped[datetime] = mapped_column(
default=datetime.now, info={DTO_KEY: dto.Attrib(mark=dto.Mark.READ_ONLY)}
)
Date/time of instance update.
from_dto
classmethod
¶
Construct an instance of the SQLAlchemy model from the Pydantic DTO.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dto_instance |
BaseModel
|
A pydantic model |
required |
Returns:
| Type | Description |
|---|---|
BaseT
|
An instance of the SQLAlchemy model. |
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 |