#![doc(hidden)]
pub mod auto;
pub mod index;
pub mod newtype;
pub mod shared_column;
pub mod storage;
pub mod version;
pub mod via;
pub use crate::schema::inventory;
pub use crate::{
Db, Error, Executor, Result, Statement,
schema::{
Auto, Deferred, DiscoverItem, Embed, Field, Load, Model, QueryMany, QueryOne,
QueryOptionOne, RelationManyField, RelationOneField, Scope, ViaMany, ViaManyField, ViaPath,
ViaTarget, generate_unique_id,
},
stmt::CreateMany,
stmt::{self, Assign, IntoExpr, IntoInsert, IntoStatement, List, Path},
update_target::UpdateTarget,
};
#[cfg(feature = "serde")]
pub use serde_json;
pub use std::{clone::Clone, convert::Into, default::Default, option::Option};
pub use self::version::Version;
pub use toasty_core as core;
pub type FieldExprTarget<F> = <F as Field>::ExprTarget;
pub fn scope_fields<S: Scope>(_scope: &S) -> S::Path<S::Item> {
S::new_path_root()
}
pub fn create_in_scope<S: Scope>(scope: S) -> S::Create {
S::create_in_scope(scope)
}
pub fn into_untyped_expr<T, V: IntoExpr<T>>(value: V) -> core::stmt::Expr {
let expr: stmt::Expr<T> = value.into_expr();
expr.into()
}
pub async fn relation_insert<M, E>(
mut query: stmt::Query<List<M>>,
executor: &mut dyn Executor,
item: E,
) -> Result<()>
where
M: Model,
E: IntoExpr<M>,
{
match query.take_via_assoc() {
Some(untyped) if untyped.path.projection.as_slice().len() == 1 => {
let assoc = stmt::Association::<List<M>>::from_untyped(untyped);
executor.exec(assoc.insert(item)).await
}
Some(_) => Err(Error::unsupported_feature(
"insert is not supported on multi-step relation traversals",
)),
None => Err(Error::unsupported_feature(
"insert requires a relation-scoped query",
)),
}
}
pub async fn relation_remove<M, E>(
mut query: stmt::Query<List<M>>,
executor: &mut dyn Executor,
item: E,
) -> Result<()>
where
M: Model,
E: IntoExpr<M>,
{
match query.take_via_assoc() {
Some(untyped) if untyped.path.projection.as_slice().len() == 1 => {
let assoc = stmt::Association::<List<M>>::from_untyped(untyped);
executor.exec(assoc.remove(item)).await
}
Some(_) => Err(Error::unsupported_feature(
"remove is not supported on multi-step relation traversals",
)),
None => Err(Error::unsupported_feature(
"remove requires a relation-scoped query",
)),
}
}
pub fn chain_or_build_many<Source, Target>(
mut query: stmt::Query<List<Source>>,
field_offset: usize,
path: stmt::Path<Source, List<Target>>,
) -> stmt::Association<List<Target>>
where
Source: Model,
Target: Model,
{
match query.take_via_assoc() {
Some(untyped) => stmt::Association::<List<Source>>::from_untyped(untyped)
.chain_field::<Target>(field_offset),
None => stmt::Association::many(query, path),
}
}
pub fn chain_or_build_many_via_one<Source, Target>(
mut query: stmt::Query<List<Source>>,
field_offset: usize,
path: stmt::Path<Source, Target>,
) -> stmt::Association<List<Target>>
where
Source: Model,
Target: Model,
{
match query.take_via_assoc() {
Some(untyped) => stmt::Association::<List<Source>>::from_untyped(untyped)
.chain_field::<Target>(field_offset),
None => stmt::Association::many_via_one(query, path),
}
}