pub trait ToqlApi where
    Self::Error: From<ToqlError>, 
{ type Row; type Error; fn insert_one<'life0, 'life1, 'async_trait, T>(
        &'life0 mut self,
        entity: &'life1 mut T,
        paths: Paths
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
    where
        T: Insert,
        T: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
; fn insert_many<'life0, 'life1, 'async_trait, T, Q>(
        &'life0 mut self,
        entities: &'life1 mut [Q],
        paths: Paths
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
    where
        T: Insert,
        Q: BorrowMut<T> + Send,
        T: 'async_trait,
        Q: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
; fn update_one<'life0, 'life1, 'async_trait, T>(
        &'life0 mut self,
        entity: &'life1 mut T,
        fields: Fields
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
    where
        T: Update + Keyed,
        T: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
; fn update_many<'life0, 'life1, 'async_trait, T, Q>(
        &'life0 mut self,
        entities: &'life1 mut [Q],
        fields: Fields
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
    where
        T: Update + Keyed,
        Q: BorrowMut<T> + Send + Sync,
        T: 'async_trait,
        Q: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
; fn load_one<'life0, 'async_trait, T, B>(
        &'life0 mut self,
        query: B
    ) -> Pin<Box<dyn Future<Output = Result<T, Self::Error>> + Send + 'async_trait>>
    where
        T: Load<Self::Row, Self::Error>,
        B: Borrow<Query<T>> + Send + Sync,
        <T as Keyed>::Key: FromRow<Self::Row, Self::Error>,
        T: 'async_trait,
        B: 'async_trait,
        'life0: 'async_trait,
        Self: 'async_trait
; fn load_many<'life0, 'async_trait, T, B>(
        &'life0 mut self,
        query: B
    ) -> Pin<Box<dyn Future<Output = Result<Vec<T>, Self::Error>> + Send + 'async_trait>>
    where
        T: Load<Self::Row, Self::Error>,
        B: Borrow<Query<T>> + Send + Sync,
        <T as Keyed>::Key: FromRow<Self::Row, Self::Error>,
        T: 'async_trait,
        B: 'async_trait,
        'life0: 'async_trait,
        Self: 'async_trait
; fn load_page<'life0, 'async_trait, T, B>(
        &'life0 mut self,
        query: B,
        page: Page
    ) -> Pin<Box<dyn Future<Output = Result<(Vec<T>, Option<PageCounts>), Self::Error>> + Send + 'async_trait>>
    where
        T: Load<Self::Row, Self::Error>,
        B: Borrow<Query<T>> + Send + Sync,
        <T as Keyed>::Key: FromRow<Self::Row, Self::Error>,
        T: 'async_trait,
        B: 'async_trait,
        'life0: 'async_trait,
        Self: 'async_trait
; fn count<'life0, 'async_trait, T, B>(
        &'life0 mut self,
        query: B
    ) -> Pin<Box<dyn Future<Output = Result<u64, Self::Error>> + Send + 'async_trait>>
    where
        T: Count,
        B: Borrow<Query<T>> + Send + Sync,
        T: 'async_trait,
        B: 'async_trait,
        'life0: 'async_trait,
        Self: 'async_trait
; fn delete_one<'life0, 'async_trait, K>(
        &'life0 mut self,
        key: K
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
    where
        K: Key + Into<Query<<K as Key>::Entity>> + Send,
        <K as Key>::Entity: Send + Delete,
        K: 'async_trait,
        'life0: 'async_trait,
        Self: 'async_trait
; fn delete_many<'life0, 'async_trait, T, B>(
        &'life0 mut self,
        query: B
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
    where
        T: Delete,
        B: Borrow<Query<T>> + Send + Sync,
        T: 'async_trait,
        B: 'async_trait,
        'life0: 'async_trait,
        Self: 'async_trait
; }
Expand description

Every database provider implements this trait. This ensures that the user of Toql can easily switch databases.

The trait can also be used to write database independend code. This however requires more trait bounds and is usually less ergonomic than passing for a specific database type to the functions.

Example

The following code shows the function signature to load an entity MyUser from a any database:

use toql_core::{error::ToqlError, toql_api::ToqlApi, load::Load, from_row::FromRow};
use toql_derive::Toql;

struct MyError;

#[derive(Toql)]
struct MyUser {
   #[toql(key)]
   id: u64,
   name: String
}

async fn load_user<R, E, A>(toql: &mut A) -> std::result::Result<Vec<MyUser>, MyError>
where A: ToqlApi<Row=R, Error = E>,
    E: From<ToqlError>,
    MyUser: Load<R, E>,
    <User as Keyed>::Key: FromRow<R, E>,  // Needed until rust-lang/rfcs#2289 is resolved
    MyError: From<E>
{
       let users = toql.load_many().await?;
       Ok(users)
}

Required Associated Types

Required Methods

Implementors