use crate::dsl; #[cfg(feature = "postgres_backend")] use crate::expression::SelectableExpression; use crate::expression::TypedExpressionType; use crate::expression::ValidGrouping; use crate::query_builder::FromClause; use crate::query_builder::{AsQuery, SelectStatement}; use crate::query_source::Table; use crate::Expression; /// The `distinct` method /// /// This trait should not be relied on directly by most apps. Its behavior is /// provided by [`QueryDsl`]. However, you may need a where clause on this trait /// to call `distinct` from generic code. /// /// [`QueryDsl`]: crate::QueryDsl #[diagnostic::on_unimplemented( note = "a `DISTINCT` clause is not compatible with various other clauses like `LOCKING` clauses" )] pub trait DistinctDsl { /// The type returned by `.distinct` type Output; /// See the trait documentation. fn distinct(self) -> dsl::Distinct; } #[diagnostic::do_not_recommend] impl DistinctDsl for T where T: Table + AsQuery>>, T::DefaultSelection: Expression + ValidGrouping<()>, T::SqlType: TypedExpressionType, { type Output = dsl::Distinct>>; fn distinct(self) -> dsl::Distinct>> { self.as_query().distinct() } } /// The `distinct_on` method /// /// This trait should not be relied on directly by most apps. Its behavior is /// provided by [`QueryDsl`]. However, you may need a where clause on this trait /// to call `distinct_on` from generic code. /// /// [`QueryDsl`]: crate::QueryDsl #[cfg(feature = "postgres_backend")] #[diagnostic::on_unimplemented( note = "a `DISTINCT ON` clause is not compatible with various other clauses like `LOCKING` clauses", note = "a `DISTINCT ON` clause also disallows mixing aggregate and non-aggregate expressions with the `SELECT` clause" )] pub trait DistinctOnDsl { /// The type returned by `.distinct_on` type Output; /// See the trait documentation fn distinct_on(self, selection: Selection) -> dsl::DistinctOn; } #[cfg(feature = "postgres_backend")] #[diagnostic::do_not_recommend] impl DistinctOnDsl for T where Selection: SelectableExpression, T: Table + AsQuery>>, SelectStatement>: DistinctOnDsl, T::DefaultSelection: Expression + ValidGrouping<()>, T::SqlType: TypedExpressionType, { type Output = dsl::DistinctOn>, Selection>; fn distinct_on(self, selection: Selection) -> dsl::DistinctOn { self.as_query().distinct_on(selection) } }