Backend

Trait Backend 

Source
pub trait Backend: Send + Sync {
    type TM: TypeMapper;

    // Required methods
    fn type_mapper(&self) -> &Self::TM;
    fn execute_raw<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        query: &'life1 str,
        params: Option<&'life2 [LuhParam<'life2>]>,
    ) -> Pin<Box<dyn Future<Output = LuhTwin<u64>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn fetch_all_raw<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        query: &'life1 str,
        params: Option<&'life2 [LuhParam<'life2>]>,
    ) -> Pin<Box<dyn Future<Output = LuhTwin<Vec<LuhRow>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn get_master_table<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = LuhTwin<Vec<TableData>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

§Backend

This is main abstraction around DBs at codegen in LuhOrm Any type you would want to pass into Codegen has to implement this trait sqlx::Pool<Sqlite> and sqlx::Pool<Postgres> implementations have been given for you

§Expected Types

§type TM: TypeMapper

This must be set to this DB’s related type mapper

§Expected Methods

§fn type_mapper(&self) -> &Self::TM

This is expected to return the related type mapper with this DB type

§async fn execute_raw(&self, query: &str, params: Params<'_>) -> LuhTwin<u64>

This function is expected to exectute a raw query and respect params if they were set

§async fn fetch_all_raw(&self, query: &str, params: Params<'_>) -> LuhTwin<Vec<LuhRow>>

This function is expected to fetch a raw query and respect params if they were set and then return a Vec

§async fn get_master_table(&self) -> LuhTwin<Vec<TableData>>

This function is expected to introspect the DB and then return a a Vec of TableData

NOTE: if you are writing your own implementation of this for a new database type if you want foreign keys to be bidirectional then you must duplicate foreign keys and add them not only to the TableData of which the foreign key belongs to but also to foreign key’s table it references (ref_table) in order for bidirectional functionality to work it also expects the foreign key’s is_return boolean to be turned to true when that key is duplicated

Required Associated Types§

Source

type TM: TypeMapper

This is just the type of what is to be returned by Backend::type_mapper()

Required Methods§

Source

fn type_mapper(&self) -> &Self::TM

This is expected to return the related type mapper with this DB type

Source

fn execute_raw<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, query: &'life1 str, params: Option<&'life2 [LuhParam<'life2>]>, ) -> Pin<Box<dyn Future<Output = LuhTwin<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

This function is expected to exectute a raw query and respect params if they were set

Source

fn fetch_all_raw<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, query: &'life1 str, params: Option<&'life2 [LuhParam<'life2>]>, ) -> Pin<Box<dyn Future<Output = LuhTwin<Vec<LuhRow>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

This function is expected to fetch a raw query and respect params if they were set and then return a Vec

Source

fn get_master_table<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = LuhTwin<Vec<TableData>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

This function is expected to introspect the DB and then return a a Vec of TableData

NOTE: if you are writing your own implementation of this for a new database type if you want foreign keys to be bidirectional then you must duplicate foreign keys and add them not only to the TableData of which the foreign key belongs to but also to foreign key’s table it references (ref_table) in order for bidirectional functionality to work it also expects the foreign key’s is_return boolean to be turned to true when that key is duplicated

Implementations on Foreign Types§

Source§

impl Backend for Pool<Postgres>

Source§

type TM = PostgresMapper

Source§

fn type_mapper(&self) -> &Self::TM

Source§

fn fetch_all_raw<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, query: &'life1 str, params: Option<&'life2 [LuhParam<'life2>]>, ) -> Pin<Box<dyn Future<Output = LuhTwin<Vec<LuhRow>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn execute_raw<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, query: &'life1 str, params: Option<&'life2 [LuhParam<'life2>]>, ) -> Pin<Box<dyn Future<Output = LuhTwin<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn get_master_table<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = LuhTwin<Vec<TableData>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

impl Backend for Pool<Sqlite>

Source§

type TM = SqliteMapper

Source§

fn type_mapper(&self) -> &Self::TM

Source§

fn fetch_all_raw<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, query: &'life1 str, params: Option<&'life2 [LuhParam<'life2>]>, ) -> Pin<Box<dyn Future<Output = LuhTwin<Vec<LuhRow>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn execute_raw<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, query: &'life1 str, params: Option<&'life2 [LuhParam<'life2>]>, ) -> Pin<Box<dyn Future<Output = LuhTwin<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn get_master_table<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = LuhTwin<Vec<TableData>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Implementors§