GenericExecutor

Trait GenericExecutor 

Source
pub trait GenericExecutor<T> {
    // Required methods
    fn fetch_one_as<'life0, 'async_trait>(
        self,
        pool: &'life0 Pool,
    ) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn fetch_all_as<'life0, 'async_trait>(
        self,
        pool: &'life0 Pool,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: '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<'life0, 'async_trait>( self, pool: &'life0 Pool, ) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

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

Source

fn fetch_all_as<'life0, 'async_trait>( self, pool: &'life0 Pool, ) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Executes the query and returns all rows mapped as T.

Implementors§

Source§

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