1 use expression::Expression; 2 use query_builder::{AsQuery, Query}; 3 use query_source::Table; 4 5 /// This trait is not yet part of Diesel's public API. It may change in the 6 /// future without a major version bump. 7 /// 8 /// This trait exists as a stop-gap for users who need to use `GROUP BY` in 9 /// their queries, so that they are not forced to drop entirely to raw SQL. The 10 /// arguments to `group_by` are not checked, nor is the select statement 11 /// forced to be valid. 12 /// 13 /// Since Diesel otherwise assumes that you have no `GROUP BY` clause (which 14 /// would mean that mixing an aggregate and non aggregate expression in the same 15 /// query is an error), you may need to use `sql` for your select clause. 16 pub trait GroupByDsl<Expr: Expression> { 17 /// The type returned by `.group_by` 18 type Output: Query; 19 20 /// See the trait documentation. group_by(self, expr: Expr) -> Self::Output21 fn group_by(self, expr: Expr) -> Self::Output; 22 } 23 24 impl<T, Expr> GroupByDsl<Expr> for T 25 where 26 Expr: Expression, 27 T: Table + AsQuery, 28 T::Query: GroupByDsl<Expr>, 29 { 30 type Output = <T::Query as GroupByDsl<Expr>>::Output; 31 group_by(self, expr: Expr) -> Self::Output32 fn group_by(self, expr: Expr) -> Self::Output { 33 self.as_query().group_by(expr) 34 } 35 } 36