diesel/query_builder/nodes/
mod.rs
1use crate::backend::DieselReserveSpecialization;
2use crate::query_builder::*;
3use std::marker::PhantomData;
4
5#[doc(hidden)] pub trait StaticQueryFragment {
7 type Component: 'static;
8 const STATIC_COMPONENT: &'static Self::Component;
9}
10
11#[derive(Debug, Copy, Clone)]
12#[doc(hidden)] pub struct StaticQueryFragmentInstance<T>(PhantomData<T>);
14
15impl<T> StaticQueryFragmentInstance<T> {
16 #[doc(hidden)] pub const fn new() -> Self {
18 Self(PhantomData)
19 }
20}
21
22impl<T, DB> QueryFragment<DB> for StaticQueryFragmentInstance<T>
23where
24 DB: Backend + DieselReserveSpecialization,
25 T: StaticQueryFragment,
26 T::Component: QueryFragment<DB>,
27{
28 fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, DB>) -> QueryResult<()> {
29 T::STATIC_COMPONENT.walk_ast(pass)
30 }
31}
32
33#[derive(Debug, Copy, Clone)]
34#[doc(hidden)] pub struct Identifier<'a>(pub &'a str);
36
37impl<DB: Backend> QueryFragment<DB> for Identifier<'_> {
38 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
39 out.push_identifier(self.0)
40 }
41}
42
43pub trait MiddleFragment<DB: Backend> {
44 fn push_sql(&self, pass: AstPass<'_, '_, DB>);
45}
46
47impl<DB: Backend> MiddleFragment<DB> for &str {
48 fn push_sql(&self, mut pass: AstPass<'_, '_, DB>) {
49 pass.push_sql(self);
50 }
51}
52
53#[derive(Debug, Copy, Clone)]
54#[doc(hidden)] pub struct InfixNode<T, U, M> {
56 lhs: T,
57 rhs: U,
58 middle: M,
59}
60
61impl<T, U, M> InfixNode<T, U, M> {
62 #[doc(hidden)] pub const fn new(lhs: T, rhs: U, middle: M) -> Self {
64 InfixNode { lhs, rhs, middle }
65 }
66}
67
68impl<T, U, DB, M> QueryFragment<DB> for InfixNode<T, U, M>
69where
70 DB: Backend + DieselReserveSpecialization,
71 T: QueryFragment<DB>,
72 U: QueryFragment<DB>,
73 M: MiddleFragment<DB>,
74{
75 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
76 self.lhs.walk_ast(out.reborrow())?;
77 self.middle.push_sql(out.reborrow());
78 self.rhs.walk_ast(out.reborrow())?;
79 Ok(())
80 }
81}