Expand description
Mapping between the app layer and the database layer. Mapping between app-level models and database-level tables.
The types in this module define how each model field corresponds to one or more database columns. The mapping supports:
- Primitive fields that map 1:1 to a column
- Embedded structs that flatten into multiple columns
- Embedded enums stored as a discriminant column plus per-variant data columns
- Relation fields that have no direct column storage
The root type is Mapping, which holds a [Model] entry for each model.
Each Model contains per-field [Field] mappings and the expression
templates ([Model::model_to_table] and [TableToModel]) used during
query lowering.
§Examples
ⓘ
use toasty_core::schema::mapping::Mapping;
// Access the mapping for a specific model
let model_mapping = mapping.model(model_id);
println!("backed by table {:?}", model_mapping.table);Structs§
- Enum
Variant - Mapping for a single variant of an embedded enum.
- Field
Enum - Maps an embedded enum field to its discriminant column and per-variant data columns.
- Field
Primitive - Maps a primitive field to its table column.
- Field
Relation - Maps a relation field (
BelongsTo,HasMany,HasOne). - Field
Struct - Maps an embedded struct field to its flattened column representation.
- Mapping
- Defines the correspondence between app-level models and database-level tables.
- Model
- Defines the bidirectional mapping between a single model and its backing table.
- Table
ToModel - Expression template for converting table rows into model records.
Enums§
- Field
- Maps a model field to its database storage representation.