1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
macro_rules! simple_clause {
    (
        $(#[$no_clause_meta: meta])*
        $no_clause:ident,
        $(#[$clause_meta: meta])*
        $clause:ident,
        $sql:expr
    ) => {
        simple_clause!(
            $(#[$no_clause_meta])*
            $no_clause,
            $(#[$clause_meta])*
            $clause,
            $sql,
            backend_bounds =
        );
    };

    (
        $(#[$no_clause_meta: meta])*
        $no_clause:ident,
        $(#[$clause_meta: meta])*
        $clause:ident,
        $sql:expr,
        backend_bounds = $($backend_bounds:ident),*
    ) => {
        use crate::backend::{Backend, DieselReserveSpecialization};
        use crate::result::QueryResult;
        use crate::query_builder::QueryId;
        use super::{QueryFragment, AstPass};

        $(#[$no_clause_meta])*
        #[derive(Debug, Clone, Copy, QueryId)]
        pub struct $no_clause;

        impl<DB> QueryFragment<DB> for $no_clause where
            DB: Backend + DieselReserveSpecialization,
        {
            fn walk_ast<'b>(&'b self, _: AstPass<'_, 'b, DB>) -> QueryResult<()>
            {
                Ok(())
            }
        }

        $(#[$clause_meta])*
        #[derive(Debug, Clone, Copy, QueryId)]
        pub struct $clause<Expr>(pub Expr);

        impl<Expr, DB> QueryFragment<DB> for $clause<Expr> where
            DB: Backend + DieselReserveSpecialization $(+ $backend_bounds)*,
            Expr: QueryFragment<DB>,
        {
            fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()>
            {
                out.push_sql($sql);
                self.0.walk_ast(out.reborrow())?;
                Ok(())
            }
        }
    }
}