Models API#

fastapi_restly.models provides the SQLAlchemy declarative base classes and mixins (DataclassBase, IDBase, IDMixin, TimestampsMixin) that Restly models are declared against.

class fastapi_restly.models.DataclassBase(**kwargs: Any)#

Bases: AsyncAttrs, TableNameMixin, MappedAsDataclass, DeclarativeBase

SQLAlchemy declarative base with dataclass semantics.

AsyncAttrs adds awaitable_attrs, so an unloaded attribute can be reached from plain async code – await obj.awaitable_attrs.items – where a bare obj.items would raise MissingGreenlet. Views eager-load what the response schema names, so this is for the code that runs outside that: an after_commit hook, a custom business method.

registry: ClassVar[_RegistryType] = <sqlalchemy.orm.decl_api.registry object>#

Refers to the _orm.registry in use where new _orm.Mapper objects will be associated.

type_annotation_map = {<enum 'Enum'>: Enum(native_enum=False, length=64)}#
class fastapi_restly.models.IDBase(*, id: int = <sqlalchemy.orm.properties.MappedColumn object>)#

Bases: IDMixin, DataclassBase

Convenience base: DataclassBase + integer id primary key.

class fastapi_restly.models.IDMixin(*, id: int = <sqlalchemy.orm.properties.MappedColumn object>)#

Bases: MappedAsDataclass

Dataclass mixin adding an auto-incrementing integer id primary key.

id: Mapped[int] = <sqlalchemy.orm.properties.MappedColumn object>#
class fastapi_restly.models.TimestampsMixin(*, created_at: ~datetime.datetime = <sqlalchemy.orm.properties.MappedColumn object>, updated_at: ~datetime.datetime = <sqlalchemy.orm.properties.MappedColumn object>)#

Bases: MappedAsDataclass

Dataclass mixin adding UTC-aware created_at and updated_at timestamps.

created_at: Mapped[datetime] = <sqlalchemy.orm.properties.MappedColumn object>#
updated_at: Mapped[datetime] = <sqlalchemy.orm.properties.MappedColumn object>#

See also

Getting Started discusses choosing between your own DeclarativeBase and the convenience bases.