Grouping & Aggregation ====================== ``flarchitect`` can summarise datasets with SQL ``GROUP BY`` clauses and aggregate functions when explicitly enabled. This guide covers the configuration flags, supported query syntax, and how the responses are shaped. Enable support -------------- Two configuration values control the feature set: .. code-block:: python class Config: API_ALLOW_GROUPBY = True API_ALLOW_AGGREGATION = True Both flags can be applied globally on the Flask config (``API_`` prefix) or per model via the ``Meta`` class (lowercase without the prefix). Aggregation builds on grouping, so enable both together when you expect to run summaries from the same endpoint. See :doc:`configuration` for the configuration hierarchy. Group results ------------- Once ``API_ALLOW_GROUPBY`` is active, clients can pass a comma-separated ``groupby`` query parameter to select columns for the ``GROUP BY`` clause. Columns may be referenced by name or fully qualified when joins are involved:: GET /api/books?groupby=author_id GET /api/invoices?join=customer&groupby=customer.id,customer.currency When grouping is used without aggregates the result set contains the unique combinations of the requested fields. To return those fields explicitly, combine ``groupby`` with ``fields=``:: GET /api/books?fields=author_id,title&groupby=author_id Aggregate functions ------------------- ``API_ALLOW_AGGREGATION`` unlocks computed values such as totals and counts. Aggregates are expressed in the query string using the pattern:: |