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§
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>
Sourcefn create_table_stmt() -> String
fn create_table_stmt() -> String
Generate the CREATE TABLE statement for this model
Sourcefn column_definitions() -> Vec<(&'static str, &'static str)>
fn column_definitions() -> Vec<(&'static str, &'static str)>
Returns the literal raw SQL column definitions (name, type) for auto-migrations
Provided Methods§
Sourcefn create_table(executor: &mut impl Executor) -> OrmResult<()>
fn create_table(executor: &mut impl Executor) -> OrmResult<()>
Execute the CREATE TABLE statement against the database
Sourcefn find() -> QueryBuilder<Self>
fn find() -> QueryBuilder<Self>
Instantiate a QueryBuilder for this model dynamically.
Sourcefn sync_schema(executor: &mut impl Executor) -> OrmResult<()>
fn sync_schema(executor: &mut impl Executor) -> OrmResult<()>
Automatically diffs and migrates the table schema based on structural column metadata
Sourcefn insert(&mut self, executor: &mut impl Executor) -> OrmResult<()>
fn insert(&mut self, executor: &mut impl Executor) -> OrmResult<()>
Insert the model into the database. Retrieves generated columns.
Sourcefn upsert(&mut self, executor: &mut impl Executor) -> OrmResult<()>
fn upsert(&mut self, executor: &mut impl Executor) -> OrmResult<()>
Insert the model or update it if the primary key conflicts
Sourcefn update_columns(
&self,
executor: &mut impl Executor,
update_columns: &[&str],
) -> OrmResult<Self>
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.
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.