Motivation
ORM-first direction in the consuming app (Practitionist/familiarise_mobile#106): dashboard stats currently use JsonQueryBuilder .groupByFields([...]) (e.g. consultation counts by status). Delegates expose groupBy/count, but aggregations (_sum, _avg, _min, _max) are only reachable via ComputedField subqueries or raw paths.
Scope
delegate.groupBy(by: [...], where: ..., aggregate: {sum: [...], avg: [...], count: true}) returning typed maps
delegate.aggregate(...) for table-wide aggregations without grouping
- SQL compiler already supports FILTER clauses on PostgreSQL — reuse for conditional counts
Motivation
ORM-first direction in the consuming app (Practitionist/familiarise_mobile#106): dashboard stats currently use JsonQueryBuilder
.groupByFields([...])(e.g. consultation counts by status). Delegates exposegroupBy/count, but aggregations (_sum,_avg,_min,_max) are only reachable via ComputedField subqueries or raw paths.Scope
delegate.groupBy(by: [...], where: ..., aggregate: {sum: [...], avg: [...], count: true})returning typed mapsdelegate.aggregate(...)for table-wide aggregations without grouping