-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Summary
Extend aggregation support beyond .count(). Implement .sum(), .avg(), .min(), and .max() (or equivalent) so users can run aggregations in the database instead of loading all rows and computing in Python.
Current state
Status: Partially implemented.
- Implemented:
.count() - Not implemented:
.sum(),.avg(),.min(),.max()
Documentation references:
docs/coming-soon.md(Aggregation Functions)docs/guide/queries.md(lines 166-172)
Current workaround: Use .count() where possible; otherwise load records and compute aggregations in Python.
Proposed API (examples)
# Works today
total_users = await User.count()
# Does NOT work yet
total_sales = await Order.sum(Order.amount)
avg_price = await Product.avg(Product.price)
min_price = await Product.min(Product.price)
max_price = await Product.max(Product.price)- Aggregations should accept a field (or expression) and work with the existing query builder (e.g. with filters:
Order.filter(Order.status == "paid").sum(Order.amount)).
Acceptance criteria
-
.sum(field)implemented and returns a single scalar value. -
.avg(field)implemented and returns a single scalar value. -
.min(field)implemented and returns a single scalar value. -
.max(field)implemented and returns a single scalar value. - Aggregations work with filters (e.g.
.filter(...).sum(...)). - Docs updated: remove from Coming Soon and document in the queries guide alongside
.count().
Reactions are currently unavailable