protocols.dao.DaoFactoryProtocol

A protocol describing a factory to produce Data Access Objects (DAO) objects

Usage

Source

protocols.dao.DaoFactoryProtocol()

that are enclosed in transactional scopes.

Methods

Name Description
get_dao() Constructs a DAO for interacting with resources in a database.

get_dao()

Constructs a DAO for interacting with resources in a database.

Usage

Source

get_dao(*, name, dto_model, id_field, indexes=None)
Parameters
name: str

The name of the resource type (roughly equivalent to the name of a database table or collection).

dto_model: type[Dto]

A DTO (Data Transfer Object) model describing the shape of resources.

id_field: str

The name of the field of the dto_model that serves as resource ID. (DAO implementation might use this field as primary key.)

indexes: Collection[Index] | None = None
Optionally, provide any indexes that should be created in addition to the provider’s default index on id_field. Defaults to None.

Returns

A DAO specific to the provided DTO model.

Raises
self.IdFieldNotFoundError

Raised when the dto_model did not contain the expected id_field.

self.IdTypeNotSupportedError
Raised when the id_field of the dto_model has an unexpected type.