Trait pg_worm::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.

Implementors§