use crate::{Result, Statement, db::Transaction, schema::Load};
use async_trait::async_trait;
use std::sync::Arc;
use toasty_core::{Schema, stmt::Value};
#[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<Value>;
#[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 res = self.exec_untyped(stmt.untyped).await?;
T::load(res)
}
}