diesel/query_builder/
clause_macro.rs
1macro_rules! simple_clause {
2 (
3 $(#[$no_clause_meta: meta])*
4 $no_clause:ident,
5 $(#[$clause_meta: meta])*
6 $clause:ident,
7 $sql:expr
8 ) => {
9 simple_clause!(
10 $(#[$no_clause_meta])*
11 $no_clause,
12 $(#[$clause_meta])*
13 $clause,
14 $sql,
15 backend_bounds =
16 );
17 };
18
19 (
20 $(#[$no_clause_meta: meta])*
21 $no_clause:ident,
22 $(#[$clause_meta: meta])*
23 $clause:ident,
24 $sql:expr,
25 backend_bounds = $($backend_bounds:ident),*
26 ) => {
27 use crate::backend::{Backend, DieselReserveSpecialization};
28 use crate::result::QueryResult;
29 use crate::query_builder::QueryId;
30 use super::{QueryFragment, AstPass};
31
32 $(#[$no_clause_meta])*
33 #[derive(Debug, Clone, Copy, QueryId)]
34 pub struct $no_clause;
35
36 impl<DB> QueryFragment<DB> for $no_clause where
37 DB: Backend + DieselReserveSpecialization,
38 {
39 fn walk_ast<'b>(&'b self, _: AstPass<'_, 'b, DB>) -> QueryResult<()>
40 {
41 Ok(())
42 }
43 }
44
45 $(#[$clause_meta])*
46 #[derive(Debug, Clone, Copy, QueryId)]
47 pub struct $clause<Expr>(pub Expr);
48
49 impl<Expr, DB> QueryFragment<DB> for $clause<Expr> where
50 DB: Backend + DieselReserveSpecialization $(+ $backend_bounds)*,
51 Expr: QueryFragment<DB>,
52 {
53 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()>
54 {
55 out.push_sql($sql);
56 self.0.walk_ast(out.reborrow())?;
57 Ok(())
58 }
59 }
60 }
61}