pub trait Model<T>: FromRow {
// Required methods
fn columns() -> &'static [&'static dyn Deref<Target = Column>];
fn table_name() -> &'static str;
fn select<'a>() -> Select<'a, Vec<T>>;
fn select_one<'a>() -> Select<'a, Option<T>>;
fn update<'a>() -> Update<'a>;
fn delete<'a>() -> Delete<'a>;
fn query(
: impl Into<String>,
: Vec<&(dyn ToSql + Sync)>,
) -> Query<'_, Vec<T>>;
}
Expand description
This is the trait which you should derive for your model structs.
It provides the ORM functionality.
Required Methods§
Sourcefn columns() -> &'static [&'static dyn Deref<Target = Column>]
fn columns() -> &'static [&'static dyn Deref<Target = Column>]
Returns a slice of all columns this model’s table has.
Sourcefn table_name() -> &'static str
fn table_name() -> &'static str
Returns the name of this model’s table’s name.
Sourcefn select<'a>() -> Select<'a, Vec<T>>
fn select<'a>() -> Select<'a, Vec<T>>
Start building a SELECT
query which will be parsed to this model.
Sourcefn select_one<'a>() -> Select<'a, Option<T>>
fn select_one<'a>() -> Select<'a, Option<T>>
Start building a SELECT
query which returns either
one entity or None
.
Sourcefn update<'a>() -> Update<'a>
fn update<'a>() -> Update<'a>
Start building an UPDATE
query.
Returns the number of rows affected.
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.