diesel/expression/functions/aggregate_expressions/
prefix.rs1use super::AggregateExpression;
2use super::IsAggregateFunction;
3use super::NoFilter;
4use super::NoOrder;
5use super::NoWindow;
6use crate::query_builder::{AstPass, QueryFragment, QueryId};
7use crate::QueryResult;
8
9empty_clause!(NoPrefix);
10
11#[derive(Debug, Clone, Copy, QueryId)]
12pub struct All;
13
14impl<DB> QueryFragment<DB> for All
15where
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)]
25pub struct Distinct;
26
27impl<DB> QueryFragment<DB> for Distinct
28where
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
37pub trait DistinctDsl {
38 type Output;
39
40 fn distinct(self) -> Self::Output;
41}
42
43impl<T> DistinctDsl for T
44where
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
60impl<T, Prefix, Order, Filter> DistinctDsl
61 for AggregateExpression<T, Prefix, Order, Filter, NoWindow>
62where
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
78pub trait AllDsl {
79 type Output;
80
81 fn all(self) -> Self::Output;
82}
83
84impl<T> AllDsl for T
85where
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
101impl<T, Prefix, Order, Filter> AllDsl for AggregateExpression<T, Prefix, Order, Filter, NoWindow>
102where
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}