Aggregation — Aquilia Documentation
Comprehensive guide and documentation for Aggregation in the Aquilia framework. View API reference, examples, and implementation patterns.
Docs / Models / Aggregation Aggregation Computing database summary values using Sum, Avg, Count, Max, Min, and database group-by operations. Database Aggregates Aggregate functions compute summary values. Use .aggregate() for whole-table aggregates or .annotate() with .group_by() for per-group. Function SQL Notes ))} from aquilia.models.aggregate import Sum, Avg, Count, Max, Min # Whole-table aggregate stats = await Order.objects.aggregate( total=Sum("amount"), avg_amount=Avg("amount"), order_count=Count("id"), max_amount=Max("amount"), ) # → # Per-group annotation by_category = await ( Product.objects .annotate(total_sales=Sum("sales")) .group_by("category") .order("-total_sales") .values("category", "total_sales") .all() ) # → [ , ...] # PostgreSQL-specific aggregates from aquilia.models.aggregate import ArrayAgg, StringAgg grouped = await ( Tag.objects .annotate( names=ArrayAgg("name"), csv=StringAgg("name", delimiter=", "), ) .group_by("category") .values("category", "names", "csv") .all() ) Transactions Advanced );
Go to Homepage