Skip to main content

Model

Trait Model 

Source
pub trait Model:
    FromRow
    + Validate
    + Sized
    + Send
    + Sync {
Show 19 methods // Required methods fn table_name() -> &'static str; fn primary_key_columns() -> &'static [&'static str]; fn generated_columns() -> &'static [&'static str]; fn columns() -> &'static [&'static str]; fn select_clause() -> &'static str; fn primary_key_values(&self) -> Vec<PgValue>; fn set_generated_values(&mut self, values: Vec<PgValue>) -> OrmResult<()>; fn get_values(&self) -> Vec<PgValue>; fn create_table_stmt() -> String; fn column_definitions() -> Vec<(&'static str, &'static str)>; // Provided methods fn indexes() -> Vec<Index> { ... } fn create_table(executor: &mut impl Executor) -> OrmResult<()> { ... } fn find() -> QueryBuilder<Self> { ... } fn sync_schema(executor: &mut impl Executor) -> OrmResult<()> { ... } fn insert(&mut self, executor: &mut impl Executor) -> OrmResult<()> { ... } fn upsert(&mut self, executor: &mut impl Executor) -> OrmResult<()> { ... } fn update_columns( &self, executor: &mut impl Executor, update_columns: &[&str], ) -> OrmResult<Self> { ... } fn update(&self, executor: &mut impl Executor) -> OrmResult<()> { ... } fn delete(&self, executor: &mut impl Executor) -> OrmResult<()> { ... }
}

Required Methods§

Source

fn table_name() -> &'static str

Source

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

Source

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

Source

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

Source

fn select_clause() -> &'static str

Source

fn primary_key_values(&self) -> Vec<PgValue>

Source

fn set_generated_values(&mut self, values: Vec<PgValue>) -> OrmResult<()>

Source

fn get_values(&self) -> Vec<PgValue>

Source

fn create_table_stmt() -> String

Generate the CREATE TABLE statement for this model

Source

fn column_definitions() -> Vec<(&'static str, &'static str)>

Returns the literal raw SQL column definitions (name, type) for auto-migrations

Provided Methods§

Source

fn indexes() -> Vec<Index>

Returns the list of indexes to natively enforce during migrations

Source

fn create_table(executor: &mut impl Executor) -> OrmResult<()>

Execute the CREATE TABLE statement against the database

Source

fn find() -> QueryBuilder<Self>

Instantiate a QueryBuilder for this model dynamically.

Source

fn sync_schema(executor: &mut impl Executor) -> OrmResult<()>

Automatically diffs and migrates the table schema based on structural column metadata

Source

fn insert(&mut self, executor: &mut impl Executor) -> OrmResult<()>

Insert the model into the database. Retrieves generated columns.

Source

fn upsert(&mut self, executor: &mut impl Executor) -> OrmResult<()>

Insert the model or update it if the primary key conflicts

Source

fn update_columns( &self, executor: &mut impl Executor, update_columns: &[&str], ) -> OrmResult<Self>

Partially update the model, persisting only the specified columns to the database.

Source

fn update(&self, executor: &mut impl Executor) -> OrmResult<()>

Update the model in the database matching its primary key.

Source

fn delete(&self, executor: &mut impl Executor) -> OrmResult<()>

Delete the model from the database.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§