use crate::executor::{DBSession, DbError};
use crate::interfaces::Record;
use crate::placeholders::Dialect;
use super::super::plan::QueryPlan;
use super::{
BatchInsert, BatchUpsert, Insert, OwnedBatchInsert, OwnedBatchUpsert, OwnedInsert, OwnedUpdate,
Update,
};
use crate::QueryError;
impl<T> OwnedInsert<T>
where
T: Record,
{
pub fn plan(&self, dialect: Dialect) -> Result<QueryPlan, QueryError> {
self.scope.plan_insert(&&self.row, dialect)
}
pub async fn exec<S>(self, session: &mut S) -> Result<u64, DbError>
where
S: DBSession,
{
Insert {
scope: self.scope,
row: &self.row,
}
.exec(session)
.await
}
}
impl<T> OwnedUpdate<T>
where
T: Record,
{
pub fn plan(&self, dialect: Dialect) -> Result<QueryPlan, QueryError> {
self.scope.plan_update(&&self.row, dialect)
}
pub async fn exec<S>(self, session: &mut S) -> Result<u64, DbError>
where
S: DBSession,
{
Update {
scope: self.scope,
row: &self.row,
}
.exec(session)
.await
}
}
impl<T> OwnedBatchInsert<T>
where
T: Record + 'static,
{
pub fn plan(&self, dialect: Dialect) -> Result<QueryPlan, QueryError> {
self.scope.plan_batch_insert(&self.rows, dialect)
}
pub async fn exec<S>(self, session: &mut S) -> Result<u64, DbError>
where
S: DBSession,
{
BatchInsert {
scope: self.scope,
rows: &self.rows,
}
.exec(session)
.await
}
}
impl<T> OwnedBatchUpsert<T>
where
T: Record + 'static,
{
pub fn plan(&self, dialect: Dialect) -> Result<QueryPlan, QueryError> {
self.scope
.plan_batch_upsert(&self.rows, self.conflict.clone(), dialect)
}
pub async fn exec<S>(self, session: &mut S) -> Result<u64, DbError>
where
S: DBSession,
{
BatchUpsert {
scope: self.scope,
rows: &self.rows,
conflict: self.conflict,
}
.exec(session)
.await
}
}