diesel/query_dsl/
distinct_dsl.rs1use crate::dsl;
2#[cfg(feature = "postgres_backend")]
3use crate::expression::SelectableExpression;
4use crate::expression::TypedExpressionType;
5use crate::expression::ValidGrouping;
6use crate::query_builder::FromClause;
7use crate::query_builder::{AsQuery, SelectStatement};
8use crate::query_source::Table;
9use crate::Expression;
10
11#[diagnostic::on_unimplemented(
19 note = "a `DISTINCT` clause is not compatible with various other clauses like `LOCKING` clauses"
20)]
21pub trait DistinctDsl {
22 type Output;
24
25 fn distinct(self) -> dsl::Distinct<Self>;
27}
28
29#[diagnostic::do_not_recommend]
30impl<T> DistinctDsl for T
31where
32 T: Table + AsQuery<Query = SelectStatement<FromClause<T>>>,
33 T::DefaultSelection: Expression<SqlType = T::SqlType> + ValidGrouping<()>,
34 T::SqlType: TypedExpressionType,
35{
36 type Output = dsl::Distinct<SelectStatement<FromClause<T>>>;
37
38 fn distinct(self) -> dsl::Distinct<SelectStatement<FromClause<T>>> {
39 self.as_query().distinct()
40 }
41}
42
43#[cfg(feature = "postgres_backend")]
51#[diagnostic::on_unimplemented(
52 note = "a `DISTINCT ON` clause is not compatible with various other clauses like `LOCKING` clauses",
53 note = "a `DISTINCT ON` clause also disallows mixing aggregate and non-aggregate expressions with the `SELECT` clause"
54)]
55pub trait DistinctOnDsl<Selection> {
56 type Output;
58
59 fn distinct_on(self, selection: Selection) -> dsl::DistinctOn<Self, Selection>;
61}
62
63#[cfg(feature = "postgres_backend")]
64#[diagnostic::do_not_recommend]
65impl<T, Selection> DistinctOnDsl<Selection> for T
66where
67 Selection: SelectableExpression<T>,
68 T: Table + AsQuery<Query = SelectStatement<FromClause<T>>>,
69 SelectStatement<FromClause<T>>: DistinctOnDsl<Selection>,
70 T::DefaultSelection: Expression<SqlType = T::SqlType> + ValidGrouping<()>,
71 T::SqlType: TypedExpressionType,
72{
73 type Output = dsl::DistinctOn<SelectStatement<FromClause<T>>, Selection>;
74
75 fn distinct_on(self, selection: Selection) -> dsl::DistinctOn<Self, Selection> {
76 self.as_query().distinct_on(selection)
77 }
78}