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§
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.