dto

class advanced_alchemy.extensions.litestar.dto.SQLAlchemyDTO[source]

Bases: AbstractDTO, Generic[T]

Support for domain modelling with SQLAlchemy.

config: ClassVar[SQLAlchemyDTOConfig]

Config objects to define properties of the DTO.

classmethod get_property_fields(model_type)[source]

Get fields defined as @property or @cached_property on the model.

Uses inspect.getmembers() to detect properties from the model class and mixins. Properties are marked read-only; setter support is not implemented.

Parameters:
  • model_type (type[sqlalchemy.orm.DeclarativeBase]) – The SQLAlchemy model type to extract properties from.

  • model_type (type[TypeAliasForwardRef('sqlalchemy.orm.DeclarativeBase')])

Return type:

dict[str, FieldDefinition]

Returns:

A dictionary mapping property names to their field definitions.

classmethod generate_field_definitions(model_type)[source]

Generate DTO field definitions from a SQLAlchemy model.

Parameters:
Yields:

collections.abc.Generator[litestar.dto.data_structures.DTOFieldDefinition, None, None] – A generator yielding DTO field definitions.

Raises:

RuntimeError – If the mapper cannot be found for the model type.

Return type:

Generator[DTOFieldDefinition, None, None]

classmethod detect_nested_field(field_definition)[source]

Return True if field_definition represents a nested model field.

Parameters:
Return type:

bool

Returns:

True if field_definition represents a nested model field.