use super::{Expr, IntoExpr, IntoStatement, Statement};
use crate::schema::Load;
use crate::{Executor, Result};
use toasty_core::stmt;
pub struct Batch<T> {
stmt: Statement<T>,
}
pub fn batch<Q: IntoStatement>(queries: Q) -> Batch<Q::Returning>
where
Q::Returning: Load,
{
Batch {
stmt: queries.into_statement(),
}
}
impl<T: Load> Batch<T> {
pub async fn exec(self, executor: &mut dyn Executor) -> Result<T::Output> {
executor.exec(self.stmt).await
}
}
impl<T> From<Statement<T>> for Batch<T> {
fn from(stmt: Statement<T>) -> Self {
Batch { stmt }
}
}
impl<T> IntoExpr<T> for Batch<T> {
fn into_expr(self) -> Expr<T> {
Expr::from_untyped(stmt::Expr::stmt(self.stmt.untyped))
}
fn by_ref(&self) -> Expr<T> {
Expr::from_untyped(stmt::Expr::stmt(self.stmt.untyped.clone()))
}
}