use crate::commons::Arguments;
use crate::executor::{DBSession, DbError};
use crate::placeholders::Dialect;
use super::super::binds::statement_from_plan;
use super::super::plan::QueryPlan;
use super::{Count, Exists, Scalar};
use crate::QueryError;
impl Count {
pub fn plan(&self, dialect: Dialect) -> Result<QueryPlan, QueryError> {
self.scope.plan_count(dialect)
}
pub async fn exec<S>(self, session: &mut S) -> Result<i64, DbError>
where
S: DBSession,
{
let stmt = statement_from_plan(self.plan(Dialect::active())?, Arguments::default())?;
session.fetch_scalar(stmt).await
}
}
impl Exists {
pub fn plan(&self, dialect: Dialect) -> Result<QueryPlan, QueryError> {
self.scope.plan_exists(dialect)
}
pub async fn exec<S>(self, session: &mut S) -> Result<bool, DbError>
where
S: DBSession,
{
let stmt = statement_from_plan(self.plan(Dialect::active())?, Arguments::default())?;
session.fetch_scalar(stmt).await
}
}
impl<V> Scalar<V> {
pub fn plan(&self, dialect: Dialect) -> Result<QueryPlan, QueryError> {
self.scope.plan_scalar(self.expr.clone(), dialect)
}
pub async fn exec<S>(self, session: &mut S) -> Result<V, DbError>
where
V: for<'d> sqlx::Decode<'d, crate::commons::Database>
+ sqlx::Type<crate::commons::Database>
+ Send
+ Unpin
+ 'static,
S: DBSession,
{
let stmt = statement_from_plan(self.plan(Dialect::active())?, Arguments::default())?;
session.fetch_scalar(stmt).await
}
}