use std::future::Future;
use crate::{FromRow, Query};
pub trait QueryExecutor {
type Error: std::error::Error + Send + Sync + 'static;
fn query_void(&self, query: Query) -> impl Future<Output = Result<(), Self::Error>>;
fn query_one<T: FromRow + Send + 'static>(
&self,
query: Query,
) -> impl Future<Output = Result<Option<T>, Self::Error>>;
fn query_list<T: FromRow + Send + 'static>(
&self,
query: Query,
) -> impl Future<Output = Result<Vec<T>, Self::Error>>;
fn batch(&self, scripts: &[fn() -> Query]) -> impl Future<Output = Result<(), Self::Error>> {
async move {
for script in scripts {
self.query_void(script()).await?;
}
Ok(())
}
}
}