Trait pg_worm::Model

source ·
pub trait Model<T>: for<'a> TryFrom<&'a Row> {
    // Required methods
    fn _create_table_sql() -> &'static str;
    fn select<'async_trait>(
        
    ) -> Pin<Box<dyn Future<Output = Vec<T>> + Send + 'async_trait>>;
    fn select_one<'async_trait>(
        
    ) -> Pin<Box<dyn Future<Output = Option<T>> + 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 _create_table_sql() -> &'static str

This is a library function needed to derive the Modeltrait.

DO NOT USE

source

fn select<'async_trait>( ) -> 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>( ) -> 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

Implementors§