Derive Macro diesel::expression::ValidGrouping

source ·
    // Attributes available to this derive:
Expand description

Implements ValidGrouping

This trait can be automatically derived for structs with no type parameters which are never aggregate, as well as for structs which are NonAggregate when all type parameters are NonAggregate. For example:

struct LiteralOne;

struct Plus<Lhs, Rhs>(Lhs, Rhs);

// The following impl will be generated:

impl<GroupByClause> ValidGrouping<GroupByClause> for LiteralOne {
    type IsAggregate = is_aggregate::Never;

impl<Lhs, Rhs, GroupByClause> ValidGrouping<GroupByClause> for Plus<Lhs, Rhs>
    Lhs: ValidGrouping<GroupByClause>,
    Rhs: ValidGrouping<GroupByClause>,
    Lhs::IsAggregate: MixedAggregates<Rhs::IsAggregate>,
    type IsAggregate = <Lhs::IsAggregate as MixedAggregates<Rhs::IsAggregate>>::Output;

For types which are always considered aggregate (such as an aggregate function), annotate your struct with #[diesel(aggregate)] to set IsAggregate explicitly to is_aggregate::Yes.


§Optional container attributes

  • #[diesel(aggregate)] for cases where the type represents an aggregating SQL expression