GenericExecutor

Trait GenericExecutor 

Source
pub trait GenericExecutor<T> {
    // Required methods
    fn fetch_one_as<'a, 'async_trait, A>(
        self,
        pool: A,
    ) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>
       where A: 'async_trait + Send + Acquire<'a, Database = Driver>,
             Self: 'async_trait,
             'a: 'async_trait;
    fn fetch_all_as<'a, 'async_trait, A>(
        self,
        pool: A,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + Send + 'async_trait>>
       where A: 'async_trait + Send + Acquire<'a, Database = Driver>,
             Self: 'async_trait,
             'a: 'async_trait;
}
Expand description

Executes a built query and returns typed results.

This trait is implemented for the query builder type, allowing you to fetch typed rows directly into your domain structs that implement sqlx::FromRow.

§Examples

PostgreSQL

use sqlorm_core::{qb::{QB, Column}, TableInfo, GenericExecutor, Pool};
use std::marker::PhantomData;

let base = TableInfo {
    name: "users",
    alias: "u".to_string(),
    columns: vec!["id", "name"],
};

let qb1 = QB::<()>::new(base)
    .select::<(i32, String)>(vec!["id", "name"])
    .filter(Column::<i32> {
        name: "id",
        table_alias: "u",
        aliased_name: "u__id",
        _marker: PhantomData,
    }.eq(1));

let one: (i32, String) = qb1.fetch_one_as(pool).await?;

let qb2 = QB::<()>::new(TableInfo {
    name: "users",
    alias: "u".to_string(),
    columns: vec!["id", "name"],
})
.select::<(i32, String)>(vec!["id", "name"])
.filter(Column::<i32> {
    name: "id",
    table_alias: "u",
    aliased_name: "u__id",
    _marker: PhantomData,
}.gt(0));

let many: Vec<(i32, String)> = qb2.fetch_all_as(pool).await?;

Required Methods§

Source

fn fetch_one_as<'a, 'async_trait, A>( self, pool: A, ) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>
where A: 'async_trait + Send + Acquire<'a, Database = Driver>, Self: 'async_trait, 'a: 'async_trait,

Executes the query and returns a single row mapped as T.

Source

fn fetch_all_as<'a, 'async_trait, A>( self, pool: A, ) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + Send + 'async_trait>>
where A: 'async_trait + Send + Acquire<'a, Database = Driver>, Self: 'async_trait, 'a: 'async_trait,

Executes the query and returns all rows mapped as T.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> GenericExecutor<T> for QB<T>
where T: for<'r> FromRow<'r, Row> + Send + Unpin + Debug,