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 methods
fn primary_key_auto_increment() -> bool { ... }
fn created_at_column() -> Option<&'static str> { ... }
fn updated_at_column() -> Option<&'static str> { ... }
fn soft_delete_column() -> Option<&'static str> { ... }
fn version_column() -> Option<&'static str> { ... }
}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§
Sourcefn table_name() -> &'static str
fn table_name() -> &'static str
The database table name.
Sourcefn column_names() -> &'static [&'static str]
fn column_names() -> &'static [&'static str]
All column names (excluding #[ignore] fields).
Sourcefn primary_key_name() -> &'static str
fn primary_key_name() -> &'static str
The primary key column name.
Sourcefn primary_key_value(&self) -> Value
fn primary_key_value(&self) -> Value
The primary key value for this instance.
Provided Methods§
Sourcefn primary_key_auto_increment() -> bool
fn primary_key_auto_increment() -> bool
Whether the primary key is auto-incremented by the database.
Sourcefn created_at_column() -> Option<&'static str>
fn created_at_column() -> Option<&'static str>
The column save sets to the time of the insert and never writes
again (#[timestamps]: created_at). None: no such column.
Sourcefn updated_at_column() -> Option<&'static str>
fn updated_at_column() -> Option<&'static str>
The column save sets to the time of every insert and update
(#[timestamps]: updated_at).
Sourcefn soft_delete_column() -> Option<&'static str>
fn soft_delete_column() -> Option<&'static str>
The soft-delete column (#[soft_delete]: deleted_at): delete
sets it to the time instead of removing the row, and queries leave
out rows where it isn’t NULL unless asked for them.
Sourcefn version_column() -> Option<&'static str>
fn version_column() -> Option<&'static str>
The optimistic-locking column (#[version]): 1 on insert, one
more on every update, which only succeeds while the row still has
the version this copy was read with.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".