mod association;
pub use association::Association;
mod batch;
pub use batch::{Batch, batch};
mod create_many;
pub use create_many::CreateMany;
mod delete;
pub use delete::Delete;
mod expr;
pub use expr::Expr;
mod insert;
pub use insert::Insert;
mod assignment;
pub use assignment::{Assign, Assignment, apply, insert, patch, remove, set};
mod into_expr;
pub use into_expr::IntoExpr;
mod into_insert;
pub use into_insert::IntoInsert;
mod into_statement;
pub use into_statement::IntoStatement;
mod list;
pub use list::List;
mod page;
pub use page::Page;
mod paginate;
pub use paginate::Paginate;
mod path;
pub use path::Path;
pub use crate::schema::Auto;
use crate::{Executor, schema::Load};
mod query;
pub use query::Query;
mod update;
pub use update::Update;
pub use toasty_core::stmt::{OrderBy, Projection, Value};
use toasty_core::stmt;
use std::{fmt, marker::PhantomData};
pub struct Statement<T> {
pub(crate) untyped: stmt::Statement,
_p: PhantomData<T>,
}
impl<T> Statement<T> {
pub fn from_untyped_stmt(untyped: stmt::Statement) -> Self {
Self {
untyped,
_p: PhantomData,
}
}
pub fn into_untyped(self) -> stmt::Statement {
self.untyped
}
pub(crate) fn into_untyped_query(self) -> stmt::Query {
match self.untyped {
stmt::Statement::Query(q) => q,
_ => panic!("expected query statement"),
}
}
pub fn into_query(self) -> Option<Query<T>> {
match self.untyped {
stmt::Statement::Query(q) => Some(Query::from_untyped(q)),
_ => None,
}
}
}
impl<T: Load> Statement<T> {
pub async fn exec(self, executor: &mut dyn Executor) -> crate::Result<T::Output> {
executor.exec(self).await
}
}
impl<M> From<Query<M>> for Statement<M> {
fn from(value: Query<M>) -> Self {
Self {
untyped: value.untyped.into(),
_p: PhantomData,
}
}
}
impl<M> From<Insert<M>> for Statement<M> {
fn from(value: Insert<M>) -> Self {
Self {
untyped: value.untyped.into(),
_p: PhantomData,
}
}
}
impl<M> From<Update<M>> for Statement<M> {
fn from(value: Update<M>) -> Self {
Self {
untyped: value.untyped.into(),
_p: PhantomData,
}
}
}
impl<M> fmt::Debug for Statement<M> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
self.untyped.fmt(fmt)
}
}
pub fn in_list<T>(lhs: impl IntoExpr<T>, rhs: impl IntoExpr<List<T>>) -> Expr<bool> {
Expr::from_untyped(stmt::Expr::in_list(
lhs.into_expr().untyped,
rhs.into_expr().untyped,
))
}