|
1 | | -#[macro_export] |
2 | | -#[doc(hidden)] |
3 | | -#[cfg(feature = "with-deprecated")] |
4 | | -#[deprecated( |
5 | | - since = "1.3.0", |
6 | | - note = "The syntax of `sql_function!` and its output have changed significantly. This form has been deprecated. See the documentation of `sql_function!` for details on the new syntax." |
7 | | -)] |
8 | | -macro_rules! sql_function_body { |
9 | | - ( |
10 | | - $fn_name:ident, |
11 | | - $struct_name:ident, |
12 | | - ($($arg_name:ident: $arg_type:ty),*) -> $return_type:ty, |
13 | | - $docs:expr, |
14 | | - $helper_ty_docs:expr |
15 | | - ) => { |
16 | | - #[allow(non_camel_case_types)] |
17 | | - #[derive(Debug, Clone, Copy, QueryId)] |
18 | | - #[doc(hidden)] |
19 | | - pub struct $struct_name<$($arg_name),*> { |
20 | | - $($arg_name: $arg_name),* |
21 | | - } |
22 | | - |
23 | | - #[allow(non_camel_case_types)] |
24 | | - #[doc=$helper_ty_docs] |
25 | | - pub type $fn_name<$($arg_name),*> = $struct_name<$( |
26 | | - <$arg_name as $crate::expression::AsExpression<$arg_type>>::Expression |
27 | | - ),*>; |
28 | | - |
29 | | - #[allow(non_camel_case_types)] |
30 | | - #[doc=$docs] |
31 | | - pub fn $fn_name<$($arg_name),*>($($arg_name: $arg_name),*) |
32 | | - -> $fn_name<$($arg_name),*> |
33 | | - where $($arg_name: $crate::expression::AsExpression<$arg_type>),+ |
34 | | - { |
35 | | - $struct_name { |
36 | | - $($arg_name: $arg_name.as_expression()),+ |
37 | | - } |
38 | | - } |
39 | | - |
40 | | - #[allow(non_camel_case_types)] |
41 | | - impl<$($arg_name),*> $crate::expression::Expression for $struct_name<$($arg_name),*> where |
42 | | - for <'a> ($(&'a $arg_name),*): $crate::expression::Expression, |
43 | | - { |
44 | | - type SqlType = $return_type; |
45 | | - } |
46 | | - |
47 | | - #[allow(non_camel_case_types)] |
48 | | - impl<$($arg_name),*, DB> $crate::query_builder::QueryFragment<DB> for $struct_name<$($arg_name),*> where |
49 | | - DB: $crate::backend::Backend, |
50 | | - for <'a> ($(&'a $arg_name),*): $crate::query_builder::QueryFragment<DB>, |
51 | | - { |
52 | | - fn walk_ast(&self, mut out: $crate::query_builder::AstPass<DB>) -> $crate::result::QueryResult<()> { |
53 | | - out.push_sql(concat!(stringify!($fn_name), "(")); |
54 | | - $crate::query_builder::QueryFragment::walk_ast( |
55 | | - &($(&self.$arg_name),*), out.reborrow())?; |
56 | | - out.push_sql(")"); |
57 | | - Ok(()) |
58 | | - } |
59 | | - } |
60 | | - |
61 | | - #[allow(non_camel_case_types)] |
62 | | - impl<$($arg_name),*, QS> $crate::expression::SelectableExpression<QS> for $struct_name<$($arg_name),*> where |
63 | | - $($arg_name: $crate::expression::SelectableExpression<QS>,)* |
64 | | - $struct_name<$($arg_name),*>: $crate::expression::AppearsOnTable<QS>, |
65 | | - { |
66 | | - } |
67 | | - |
68 | | - #[allow(non_camel_case_types)] |
69 | | - impl<$($arg_name),*, QS> $crate::expression::AppearsOnTable<QS> for $struct_name<$($arg_name),*> where |
70 | | - $($arg_name: $crate::expression::AppearsOnTable<QS>,)* |
71 | | - $struct_name<$($arg_name),*>: $crate::expression::Expression, |
72 | | - { |
73 | | - } |
74 | | - |
75 | | - #[allow(non_camel_case_types)] |
76 | | - impl<$($arg_name),*> $crate::expression::NonAggregate for $struct_name<$($arg_name),*> where |
77 | | - $($arg_name: $crate::expression::NonAggregate,)* |
78 | | - $struct_name<$($arg_name),*>: $crate::expression::Expression, |
79 | | - { |
80 | | - } |
81 | | - } |
82 | | -} |
83 | | - |
84 | | -#[macro_export] |
85 | | -#[doc(hidden)] |
86 | | -#[cfg(not(feature = "with-deprecated"))] |
87 | | -macro_rules! sql_function_body { |
88 | | - ($($args:tt)*) => { |
89 | | - compile_error!( |
90 | | - "You are using a deprecated form of `sql_function!`. \ |
91 | | - You must enable the `with-deprecated` feature on `diesel`." |
92 | | - ); |
93 | | - }; |
94 | | -} |
95 | | - |
96 | 1 | #[macro_export] |
97 | 2 | #[doc(hidden)] |
98 | 3 | macro_rules! __diesel_sql_function_body { |
|
0 commit comments