| 1 |
use crate::dsl; |
| 2 |
use crate::expression::Expression; |
| 3 |
use crate::expression::TypedExpressionType; |
| 4 |
use crate::expression::ValidGrouping; |
| 5 |
use crate::query_builder::FromClause; |
| 6 |
use crate::query_builder::{AsQuery, SelectStatement}; |
| 7 |
use crate::query_source::Table; |
| 8 |
|
| 9 |
/// The `group_by` method |
| 10 |
/// |
| 11 |
/// This trait should not be relied on directly by most apps. Its behavior is |
| 12 |
/// provided by [`QueryDsl`]. However, you may need a where clause on this trait |
| 13 |
/// to call `group_by` from generic code. |
| 14 |
/// |
| 15 |
/// [`QueryDsl`]: crate::QueryDsl |
| 16 |
pub trait GroupByDsl<Expr: Expression> { |
| 17 |
/// The type returned by `.group_by` |
| 18 |
type Output; |
| 19 |
|
| 20 |
/// See the trait documentation. |
| 21 |
fn group_by(self, expr: Expr) -> dsl::GroupBy<Self, Expr>; |
| 22 |
} |
| 23 |
|
| 24 |
#[diagnostic::do_not_recommend] |
| 25 |
impl<T, Expr> GroupByDsl<Expr> for T |
| 26 |
where |
| 27 |
Expr: Expression, |
| 28 |
T: Table + AsQuery<Query = SelectStatement<FromClause<T>>>, |
| 29 |
T::DefaultSelection: Expression<SqlType = T::SqlType> + ValidGrouping<()>, |
| 30 |
T::SqlType: TypedExpressionType, |
| 31 |
T::Query: GroupByDsl<Expr>, |
| 32 |
{ |
| 33 |
type Output = dsl::GroupBy<SelectStatement<FromClause<T>>, Expr>; |
| 34 |
|
| 35 |
fn group_by(self, expr: Expr) -> dsl::GroupBy<Self, Expr> { |
| 36 |
self.as_query().group_by(expr) |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
pub trait ValidDistinctForGroupBy<Selection, GroupBy> {} |