Trait pg_worm::Model

source ·
pub trait Model<T>: for<'a> TryFrom<&'a Row, Error = Error> {
    // Required methods
    fn _table_creation_sql() -> &'static str;
    fn columns() -> &'static [&'static DynCol];
    fn select<'async_trait>(
        filter: Filter
    ) -> Pin<Box<dyn Future<Output = Vec<T>> + Send + 'async_trait>>;
    fn select_one<'async_trait>(
        filter: Filter
    ) -> Pin<Box<dyn Future<Output = Option<T>> + Send + 'async_trait>>;
    fn delete<'async_trait>(
        filter: Filter
    ) -> Pin<Box<dyn Future<Output = u64> + Send + 'async_trait>>;
}
Expand description

This is the trait which you should derive for your model structs.

It provides the ORM functionality.

Required Methods§

source

fn _table_creation_sql() -> &'static str

This is a library function needed to derive the Modeltrait.

DO NOT USE

source

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

source

fn select<'async_trait>( filter: Filter ) -> Pin<Box<dyn Future<Output = Vec<T>> + Send + 'async_trait>>

Retrieve all entities from the table.

Panics

For the sake of convenience this function does not return a Result but panics instead

  • if there is no database connection
source

fn select_one<'async_trait>( filter: Filter ) -> Pin<Box<dyn Future<Output = Option<T>> + Send + 'async_trait>>

Retrieve the first entity from the database. Returns None if there are no entities present.

Panics

For the sake of convenience this function does not return a Result but panics instead

  • if there is no database connection
source

fn delete<'async_trait>( filter: Filter ) -> Pin<Box<dyn Future<Output = u64> + Send + 'async_trait>>

Delete any entity wich matches the filter.

Returns the number of rows affected.

Panic

For the sake of convenience this function does not return a Result but panics instead

  • if there is no database connection

Implementors§