Skip to main content

Model

Trait Model 

Source
pub trait Model:
    Sized
    + Send
    + Sync {
    // Required methods
    fn table_name() -> &'static str;
    fn column_names() -> &'static [&'static str];
    fn primary_key_name() -> &'static str;
    fn primary_key_value(&self) -> Value;
    fn from_row(row: &ModelRow) -> Result<Self, DbError>;
    fn to_values(&self) -> Vec<(&'static str, Value)>;

    // Provided method
    fn primary_key_auto_increment() -> bool { ... }
}
Available on crate features model-mysql or model-postgres or model-sqlite only.
Expand description

Trait generated by #[derive(Model)]. Maps a Rust struct to a database table.

Required Methods§

Source

fn table_name() -> &'static str

The database table name.

Source

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

All column names (excluding #[ignore] fields).

Source

fn primary_key_name() -> &'static str

The primary key column name.

Source

fn primary_key_value(&self) -> Value

The primary key value for this instance.

Source

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

Deserialise a database row into this type.

Source

fn to_values(&self) -> Vec<(&'static str, Value)>

Serialise this instance’s fields as (column, value) pairs. Excludes #[ignore] fields.

Provided Methods§

Source

fn primary_key_auto_increment() -> bool

Whether the primary key is auto-incremented by the database.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§