Skip to main content

Model

Trait Model 

Source
pub trait Model: Sized {
    type PrimaryKey: PrimaryKey;

Show 19 methods // Required methods fn table_name() -> &'static str; fn columns() -> &'static [&'static str]; fn primary_key() -> ModelField<Self, Self::PrimaryKey>; fn primary_key_value(&self) -> Self::PrimaryKey; fn schema() -> TableSchema; fn from_row(row: &Row) -> Result<Self, DecodeError>; fn insert_values(&self) -> Vec<InsertValue>; // Provided methods fn model_name() -> &'static str { ... } fn from_row_at(row: &Row, offset: usize) -> Result<Self, DecodeError> { ... } fn from_sqlite_row(row: &Row<'_>) -> Result<Self> { ... } fn write_protected_columns() -> &'static [&'static str] { ... } fn json_columns() -> &'static [&'static str] { ... } fn field_values(&self) -> Vec<InsertValue> { ... } fn managed_update_values() -> Vec<Assignment> { ... } fn query() -> SelectQuery<Self> { ... } fn insert() -> InsertQuery<Self> { ... } fn update() -> UpdateQuery<Self> { ... } fn delete() -> DeleteQuery<Self> { ... } fn create_table() -> CreateTableQuery<Self> { ... }
}
Expand description

Trait implemented by #[derive(Model)] for ORM models.

Required Associated Types§

Required Methods§

Source

fn table_name() -> &'static str

Source

fn columns() -> &'static [&'static str]

Source

fn primary_key() -> ModelField<Self, Self::PrimaryKey>

Returns the model’s typed primary-key field.

Source

fn primary_key_value(&self) -> Self::PrimaryKey

Source

fn schema() -> TableSchema

Source

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

Source

fn insert_values(&self) -> Vec<InsertValue>

Provided Methods§

Source

fn model_name() -> &'static str

Stable Rust model name used by migration state. It is deliberately independent from table_name() so table renames keep model identity.

Source

fn from_row_at(row: &Row, offset: usize) -> Result<Self, DecodeError>

Source

fn from_sqlite_row(row: &Row<'_>) -> Result<Self>

Adapter for direct SQLite driver queries.

Source

fn write_protected_columns() -> &'static [&'static str]

Physical columns that must not accept untrusted write values. The derive includes ImageField and Option<ImageField>; trusted ORM writes remain available for validated uploads. External write adapters enforce this metadata, just as ModelSerializer enforces image read-only behavior.

Source

fn json_columns() -> &'static [&'static str]

TEXT-backed JSON columns retain their JSON type in external codecs.

Source

fn field_values(&self) -> Vec<InsertValue>

Materialized field values keyed by physical SQL column, independently of Serde naming. Unlike insert values, these include generated keys and managed timestamps. The derive generates a complete implementation; manual models with managed fields should override this method.

Source

fn managed_update_values() -> Vec<Assignment>

Source

fn query() -> SelectQuery<Self>

Source

fn insert() -> InsertQuery<Self>

Source

fn update() -> UpdateQuery<Self>

Source

fn delete() -> DeleteQuery<Self>

Source

fn create_table() -> CreateTableQuery<Self>

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§