use crate::{Result, Statement, db::Transaction, schema::Load};
use async_trait::async_trait;
use std::sync::Arc;
use toasty_core::{Schema, driver::ExecResponse};
#[async_trait]
pub trait Executor: Send + Sync {
async fn transaction(&mut self) -> Result<Transaction<'_>>;
#[doc(hidden)]
async fn exec_untyped(&mut self, stmt: toasty_core::stmt::Statement) -> Result<ExecResponse>;
#[doc(hidden)]
fn schema(&mut self) -> &Arc<Schema>;
}
impl dyn Executor + '_ {
pub async fn exec<T: Load>(&mut self, stmt: Statement<T>) -> Result<T::Output> {
let response = self.exec_untyped(stmt.untyped).await?;
let value = response.values.collect_as_value().await?;
T::load(value)
}
}