sqlw 0.1.0

Compile-time SQL query building with schema-safe field references and automatic parameter binding
Documentation
use std::future::Future;

use crate::{FromRow, Query};

/// Async query execution contract implemented by backend executors.
pub trait QueryExecutor {
    /// Backend error type.
    type Error: std::error::Error + Send + Sync + 'static;

    /// Executes a query, discarding results.
    fn query_void(&self, query: Query) -> impl Future<Output = Result<(), Self::Error>>;

    /// Executes a query, returning at most one row.
    fn query_one<T: FromRow + Send + 'static>(
        &self,
        query: Query,
    ) -> impl Future<Output = Result<Option<T>, Self::Error>>;

    /// Executes a query, returning a list of rows.
    fn query_list<T: FromRow + Send + 'static>(
        &self,
        query: Query,
    ) -> impl Future<Output = Result<Vec<T>, Self::Error>>;

    /// Executes a sequence of queries in order.
    fn batch(&self, scripts: &[fn() -> Query]) -> impl Future<Output = Result<(), Self::Error>> {
        async move {
            for script in scripts {
                self.query_void(script()).await?;
            }
            Ok(())
        }
    }
}