Functions
_build_coercion_map
1
dict[str, type | None]
▼
Build a {field_name: target_type} map for coercible fields.
Returns ``None`` f…
_build_coercion_map
1
dict[str, type | None]
▼
def _build_coercion_map(cls: type) -> dict[str, type | None]
Build a {field_name: target_type} map for coercible fields.
ReturnsNonefor fields that don't need coercion (complex types,
generics, etc.).
Parameters
| Name | Type | Description |
|---|---|---|
cls |
type |
Returns
dict[str, type | None]
_coerce
2
Any
▼
Coerce a single value to the target type, if needed.
_coerce
2
Any
▼
def _coerce(value: Any, target: type | None) -> Any
Parameters
| Name | Type | Description |
|---|---|---|
value |
Any |
|
target |
type | None |
Returns
Any
map_row
2
T
▼
Map a dict-like row to a frozen dataclass instance.
Only passes keys that matc…
map_row
2
T
▼
def map_row(cls: type[T], row: dict[str, Any]) -> T
Map a dict-like row to a frozen dataclass instance.
Only passes keys that match dataclass fields. Extra columns are silently ignored (SELECT * is fine even if the dataclass has fewer fields).
Values are coerced to match field annotations:int, float,
bool, and strfields handle driver type mismatches automatically.
Empty strings inint/float columns coerce to 0/0.0.
RaisesTypeErrorif required fields are missing from the row.
Parameters
| Name | Type | Description |
|---|---|---|
cls |
type[T] |
|
row |
dict[str, Any] |
Returns
T
map_rows
2
list[T]
▼
Map a list of dict-like rows to frozen dataclass instances.
map_rows
2
list[T]
▼
def map_rows(cls: type[T], rows: list[dict[str, Any]]) -> list[T]
Parameters
| Name | Type | Description |
|---|---|---|
cls |
type[T] |
|
rows |
list[dict[str, Any]] |
Returns
list[T]