use crate::backend::DieselReserveSpecialization; use crate::query_builder::*; use std::marker::PhantomData; #[doc(hidden)] // used by the table macro pub trait StaticQueryFragment { type Component: 'static; const STATIC_COMPONENT: &'static Self::Component; } #[derive(Debug, Copy, Clone)] #[doc(hidden)] // used by the table macro pub struct StaticQueryFragmentInstance(PhantomData); impl StaticQueryFragmentInstance { #[doc(hidden)] // used by the table macro pub const fn new() -> Self { Self(PhantomData) } } impl QueryFragment for StaticQueryFragmentInstance where DB: Backend + DieselReserveSpecialization, T: StaticQueryFragment, T::Component: QueryFragment, { fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, DB>) -> QueryResult<()> { T::STATIC_COMPONENT.walk_ast(pass) } } #[derive(Debug, Copy, Clone)] #[doc(hidden)] // used by the table macro pub struct Identifier<'a>(pub &'a str); impl QueryFragment for Identifier<'_> { fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> { out.push_identifier(self.0) } } pub trait MiddleFragment { fn push_sql(&self, pass: AstPass<'_, '_, DB>); } impl MiddleFragment for &str { fn push_sql(&self, mut pass: AstPass<'_, '_, DB>) { pass.push_sql(self); } } #[derive(Debug, Copy, Clone)] #[doc(hidden)] // used by the table macro pub struct InfixNode { lhs: T, rhs: U, middle: M, } impl InfixNode { #[doc(hidden)] // used by the table macro pub const fn new(lhs: T, rhs: U, middle: M) -> Self { InfixNode { lhs, rhs, middle } } } impl QueryFragment for InfixNode where DB: Backend + DieselReserveSpecialization, T: QueryFragment, U: QueryFragment, M: MiddleFragment, { fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> { self.lhs.walk_ast(out.reborrow())?; self.middle.push_sql(out.reborrow()); self.rhs.walk_ast(out.reborrow())?; Ok(()) } }