Skip to content

orm

Application ORM configuration.

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.

Attributes

Mapped[datetime]

Date/time of instance creation.

Mapped[datetime]

Date/time of last instance update.

from_dto classmethod

from_dto(dto_instance)

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

touch_updated_timestamp(session, *_)

Called from SQLAlchemy's.

before_flush event to bump the updated timestamp on modified instances.

Parameters

Session

The sync Session instance that underlies the async session.