Debian Codegraph @

src/expression/functions/aggregate_expressions/prefix.rs

raw
1 use super::AggregateExpression;
2 use super::IsAggregateFunction;
3 use super::NoFilter;
4 use super::NoOrder;
5 use super::NoWindow;
6 use crate::query_builder::{AstPass, QueryFragment, QueryId};
7 use crate::QueryResult;
8
9 empty_clause!(NoPrefix);
10
11 #[derive(Debug, Clone, Copy, QueryId)]
12 pub struct All;
13
14 impl<DB> QueryFragment<DB> for All
15 where
16 DB: crate::backend::Backend,
17 {
18 fn walk_ast<'b>(&'b self, mut pass: AstPass<'_, 'b, DB>) -> QueryResult<()> {
19 pass.push_sql(" ALL ");
20 Ok(())
21 }
22 }
23
24 #[derive(Debug, Clone, Copy, QueryId)]
25 pub struct Distinct;
26
27 impl<DB> QueryFragment<DB> for Distinct
28 where
29 DB: crate::backend::Backend,
30 {
31 fn walk_ast<'b>(&'b self, mut pass: AstPass<'_, 'b, DB>) -> QueryResult<()> {
32 pass.push_sql(" DISTINCT ");
33 Ok(())
34 }
35 }
36
37 pub trait DistinctDsl {
38 type Output;
39
40 fn distinct(self) -> Self::Output;
41 }
42
43 impl<T> DistinctDsl for T
44 where
45 T: IsAggregateFunction,
46 {
47 type Output = AggregateExpression<T, Distinct>;
48
49 fn distinct(self) -> Self::Output {
50 AggregateExpression {
51 prefix: Distinct,
52 function: self,
53 order: NoOrder,
54 filter: NoFilter,
55 window: NoWindow,
56 }
57 }
58 }
59
60 impl<T, Prefix, Order, Filter> DistinctDsl
61 for AggregateExpression<T, Prefix, Order, Filter, NoWindow>
62 where
63 T: IsAggregateFunction,
64 {
65 type Output = AggregateExpression<T, Distinct, Order, Filter, NoWindow>;
66
67 fn distinct(self) -> Self::Output {
68 AggregateExpression {
69 prefix: Distinct,
70 function: self.function,
71 order: self.order,
72 filter: self.filter,
73 window: self.window,
74 }
75 }
76 }
77
78 pub trait AllDsl {
79 type Output;
80
81 fn all(self) -> Self::Output;
82 }
83
84 impl<T> AllDsl for T
85 where
86 T: IsAggregateFunction,
87 {
88 type Output = AggregateExpression<T, All>;
89
90 fn all(self) -> Self::Output {
91 AggregateExpression {
92 prefix: All,
93 function: self,
94 order: NoOrder,
95 filter: NoFilter,
96 window: NoWindow,
97 }
98 }
99 }
100
101 impl<T, Prefix, Order, Filter> AllDsl for AggregateExpression<T, Prefix, Order, Filter, NoWindow>
102 where
103 T: IsAggregateFunction,
104 {
105 type Output = AggregateExpression<T, All, Order, Filter, NoWindow>;
106
107 fn all(self) -> Self::Output {
108 AggregateExpression {
109 prefix: All,
110 function: self.function,
111 order: self.order,
112 filter: self.filter,
113 window: self.window,
114 }
115 }
116 }