from_mapped
Using this implementation instead of the starlite.SQLAlchemy
plugin DTO as
a POC for using the SQLAlchemy model type annotations to build the pydantic
model.
Also experimenting with marking columns for DTO purposes using the
SQLAlchemy.Column.info
field, which allows demarcation of fields that
should always be private, or read-only at the model declaration layer.
FromMapped ¶
Bases: BaseModel
, Generic[AnyDeclarative]
Produce an SQLAlchemy instance with values from a pydantic model.
Config ¶
Set orm_mode for to_mapped()
method.
__class_getitem__ ¶
Decorate cls
with result from factory()
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item |
Annotated[type[AnyDeclarative], DTOConfig | Literal['read', 'write']]
|
Can be either of a SQLAlchemy ORM instance, or a |
required |
Returns:
Type | Description |
---|---|
type[FromMapped[AnyDeclarative]]
|
A new Pydantic model type, with |
type[FromMapped[AnyDeclarative]]
|
from the SQLAlchemy model, respecting any declared configuration. |
__init_subclass__ ¶
to_mapped ¶
Create an instance of self.__sqla_model__
Fill the bound SQLAlchemy model recursively with values from this dataclass.