Trait Model

Source
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§

Source

fn columns() -> &'static [&'static dyn Deref<Target = Column>]

Returns a slice of all columns this model’s table has.

Source

fn table_name() -> &'static str

Returns the name of this model’s table’s name.

Source

fn select<'a>() -> Select<'a, Vec<T>>

Start building a SELECT query which will be parsed to this model.

Source

fn select_one<'a>() -> Select<'a, Option<T>>

Start building a SELECT query which returns either one entity or None.

Source

fn update<'a>() -> Update<'a>

Start building an UPDATE query.

Returns the number of rows affected.

Source

fn delete<'a>() -> Delete<'a>

Start building a DELETE query.

Returns the number or rows affected.

Source

fn query(: impl Into<String>, : Vec<&(dyn ToSql + Sync)>) -> Query<'_, Vec<T>>

Build a raw query by passing in a statement along with arguments.

You can reference the params by using ? as a placeholder.

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§