pub struct GroupByOperation<M: Model, E: QueryEngine> { /* private fields */ }Expand description
Group by operation builder.
§Engine ownership
Like AggregateOperation, holds an Option<E> so SQL-emission
unit tests compile without a real engine. Production code uses
GroupByOperation::with_engine via the generated
Client<E>::group_by accessor.
Implementations§
Source§impl<M: Model, E: QueryEngine> GroupByOperation<M, E>
impl<M: Model, E: QueryEngine> GroupByOperation<M, E>
Sourcepub fn new(columns: Vec<String>) -> Self
pub fn new(columns: Vec<String>) -> Self
Create a new group-by operation without an engine.
Useful for unit tests that only exercise Self::build_sql.
Self::exec will refuse to run on a builder created this way.
Sourcepub fn with_engine(engine: E, columns: Vec<String>) -> Self
pub fn with_engine(engine: E, columns: Vec<String>) -> Self
Create a new group-by operation bound to a concrete engine.
This is what the generated Client<E>::group_by(cols) accessor
calls.
Sourcepub fn having(self, condition: HavingCondition) -> Self
pub fn having(self, condition: HavingCondition) -> Self
Add a having condition.
Sourcepub fn order_by(self, order: impl Into<OrderByField>) -> Self
pub fn order_by(self, order: impl Into<OrderByField>) -> Self
Add ordering.
Sourcepub fn build_sql(&self, dialect: &dyn SqlDialect) -> (String, Vec<FilterValue>)
pub fn build_sql(&self, dialect: &dyn SqlDialect) -> (String, Vec<FilterValue>)
Build the SQL for this operation.
Sourcepub async fn exec(self) -> QueryResult<Vec<GroupByResult>>
pub async fn exec(self) -> QueryResult<Vec<GroupByResult>>
Execute the group-by operation.
Returns one GroupByResult per grouped row. Each result
splits the row map into two buckets:
group_values: entries whose key matches a column named ingroup_columns.aggregates: everything else — parsed throughAggregateResult::from_row.
Errors with QueryError::internal if the builder was
constructed via Self::new without an engine.