pub trait Model:
Identified
+ ApplyField
+ Clone
+ 'static {
Show 14 associated constants and 5 methods
const TABLE: &'static str;
const KEY: &'static str;
const COLUMNS: &'static [ColumnDef];
const COMPOSITE_INDEXES: &'static [&'static [&'static str]] = _;
const UNIQUE_INDEXES: &'static [&'static [&'static str]] = _;
const FTS_COLUMNS: &'static [&'static str] = _;
const FTS_TOKENIZE: Option<&'static str> = None;
const SPATIAL: Option<SpatialCols> = None;
const KEY_SQL: SqlType = SqlType::Integer;
const RELATIONS: &'static [RelationDef] = _;
const LINKS: &'static [LinkDef] = _;
const LAZY_FIELDS: &'static [&'static str] = _;
const EXTERNAL: bool = false;
const SCHEMA: Option<&'static str> = None;
// Required methods
fn to_row(&self) -> Vec<Value>;
fn from_row(row: &dyn Row) -> Result<Self, DbError>;
fn default_row() -> Vec<Value>;
// Provided methods
fn settle_lazy(&mut self) -> Vec<(&'static str, Arc<Vec<u8>>)> { ... }
fn wire(reg: &mut Registrar<'_>) { ... }
}Expand description
A persistable model: an Identified observable struct with a schema half. Implemented by
#[derive(Model)]; the container consumes it.
Required Associated Constants§
const TABLE: &'static str
Sourceconst KEY: &'static str
const KEY: &'static str
The key column’s name (the #[model(id)] field). Also the first entry of COLUMNS.
const COLUMNS: &'static [ColumnDef]
Provided Associated Constants§
Sourceconst COMPOSITE_INDEXES: &'static [&'static [&'static str]] = _
const COMPOSITE_INDEXES: &'static [&'static [&'static str]] = _
Composite indexes from struct-level #[model(index("a", "b"))].
Sourceconst UNIQUE_INDEXES: &'static [&'static [&'static str]] = _
const UNIQUE_INDEXES: &'static [&'static [&'static str]] = _
#[model(unique("a", "b"))] on the struct: multi-column UNIQUE constraints, kept as
unique indexes (day_uidx_{table}_{a}_{b}), part of the fingerprint and of the
lightweight migration.
Sourceconst FTS_COLUMNS: &'static [&'static str] = _
const FTS_COLUMNS: &'static [&'static str] = _
Full-text-indexed columns from struct-level #[model(fts("a", "b"))]: an
external-content FTS5 shadow table plus sync triggers, generated at open.
Sourceconst FTS_TOKENIZE: Option<&'static str> = None
const FTS_TOKENIZE: Option<&'static str> = None
The FTS5 tokenizer, from #[model(fts(…, tokenize = "…"))], e.g.
"unicode61 remove_diacritics 2" for diacritics-insensitive search. None keeps
FTS5’s default. Part of the schema fingerprint, so changing it rebuilds the shadow.
Sourceconst SPATIAL: Option<SpatialCols> = None
const SPATIAL: Option<SpatialCols> = None
The R*Tree pair from struct-level #[model(spatial(lat = "…", lon = "…"))].
Sourceconst KEY_SQL: SqlType = SqlType::Integer
const KEY_SQL: SqlType = SqlType::Integer
The key column’s SQL shape: what a One<Self> foreign-key column stores.
Sourceconst RELATIONS: &'static [RelationDef] = _
const RELATIONS: &'static [RelationDef] = _
Relations declared on this model’s Many fields (#[model(relation(…))]).
Sourceconst LINKS: &'static [LinkDef] = _
const LINKS: &'static [LinkDef] = _
Relations by value (#[model(link(…))]): rows of another model whose remote column
equals this row’s local column, with no foreign key: the shape that reaches across an
attached database (see ModelContainer::attach_database).
Sourceconst LAZY_FIELDS: &'static [&'static str] = _
const LAZY_FIELDS: &'static [&'static str] = _
The fields declared as Blob: the columns a fault names as NULL and the fold
writes only when they carry pending bytes.
Required Methods§
Sourcefn from_row(row: &dyn Row) -> Result<Self, DbError>
fn from_row(row: &dyn Row) -> Result<Self, DbError>
Decode one row, its columns in COLUMNS order.
§Errors
Returns a decoding error when a column holds a value its field cannot take.
Sourcefn default_row() -> Vec<Value>
fn default_row() -> Vec<Value>
Each column’s Rust-default value: what an added column backfills with.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".