Skip to main content

Model

Trait Model 

Source
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§

Source

const TABLE: &'static str

Source

const KEY: &'static str

The key column’s name (the #[model(id)] field). Also the first entry of COLUMNS.

Source

const COLUMNS: &'static [ColumnDef]

Provided Associated Constants§

Source

const COMPOSITE_INDEXES: &'static [&'static [&'static str]] = _

Composite indexes from struct-level #[model(index("a", "b"))].

Source

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.

Source

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.

Source

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.

Source

const SPATIAL: Option<SpatialCols> = None

The R*Tree pair from struct-level #[model(spatial(lat = "…", lon = "…"))].

Source

const KEY_SQL: SqlType = SqlType::Integer

The key column’s SQL shape: what a One<Self> foreign-key column stores.

Source

const RELATIONS: &'static [RelationDef] = _

Relations declared on this model’s Many fields (#[model(relation(…))]).

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).

Source

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.

Source

const EXTERNAL: bool = false

Declared external = "alias": the table belongs to a database attached under that alias and managed elsewhere. The container creates, migrates, and fingerprints nothing for it, and treats it as read-only.

Source

const SCHEMA: Option<&'static str> = None

The alias an EXTERNAL table’s database is attached under, the part TABLE is qualified with (catalog in catalog.stations). Kept apart so SQL can quote each half; None for a table in the container’s own file.

Required Methods§

Source

fn to_row(&self) -> Vec<Value>

One Value per column, in COLUMNS order.

Source

fn from_row(row: &dyn Row) -> Result<Self, DbError>

Source

fn default_row() -> Vec<Value>

Each column’s Rust-default value: what an added column backfills with.

Provided Methods§

Source

fn settle_lazy(&mut self) -> Vec<(&'static str, Arc<Vec<u8>>)>

After a flush wrote this row: hand over every lazy field’s pending bytes and mark them stored. The derive generates it for models with Blob fields.

Source

fn wire(reg: &mut Registrar<'_>)

Wire this model’s declared relations. Generated; the default declares none.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§