pub trait Model:
Identified
+ ApplyField
+ Clone
+ 'static {
const TABLE: &'static str;
const KEY: &'static str;
const COLUMNS: &'static [ColumnDef];
const COMPOSITE_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 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 method
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 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).
Required Methods§
fn from_row(row: &dyn Row) -> Result<Self, DbError>
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".