Skip to main content

Executor

Trait Executor 

Source
pub trait Executor {
    // Required methods
    fn execute_raw(
        &self,
        sql: &str,
        params: Vec<Value>,
    ) -> impl Future<Output = Result<u64, FlozError>> + Send;
    fn fetch_all<T>(
        &self,
        sql: &str,
        params: Vec<Value>,
    ) -> impl Future<Output = Result<Vec<T>, FlozError>> + Send
       where T: Send + Unpin + FlozRowBound;
    fn fetch_one<T>(
        &self,
        sql: &str,
        params: Vec<Value>,
    ) -> impl Future<Output = Result<T, FlozError>> + Send
       where T: Send + Unpin + FlozRowBound;
    fn fetch_optional<T>(
        &self,
        sql: &str,
        params: Vec<Value>,
    ) -> impl Future<Output = Result<Option<T>, FlozError>> + Send
       where T: Send + Unpin + FlozRowBound;
}
Expand description

The core database execution trait.

All floz DAO and DSL methods accept &impl Executor, allowing seamless switching between connection pools, transactions, and mocks.

// Both work:
let users = User::all(&db).await?;
let users = User::all(&tx).await?;

Required Methods§

Source

fn execute_raw( &self, sql: &str, params: Vec<Value>, ) -> impl Future<Output = Result<u64, FlozError>> + Send

Execute a raw SQL statement, returning the number of affected rows.

Source

fn fetch_all<T>( &self, sql: &str, params: Vec<Value>, ) -> impl Future<Output = Result<Vec<T>, FlozError>> + Send
where T: Send + Unpin + FlozRowBound,

Fetch all matching rows.

Source

fn fetch_one<T>( &self, sql: &str, params: Vec<Value>, ) -> impl Future<Output = Result<T, FlozError>> + Send
where T: Send + Unpin + FlozRowBound,

Fetch exactly one row. Returns FlozError::NotFound if no rows match.

Source

fn fetch_optional<T>( &self, sql: &str, params: Vec<Value>, ) -> impl Future<Output = Result<Option<T>, FlozError>> + Send
where T: Send + Unpin + FlozRowBound,

Fetch zero or one row.

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§