client.aggregate
Run an aggregate query (count, sum, avg, min, max)
Signature
class Client {
aggregate<T>(table: string, opts: { fn: string; column?: string; groupBy?: string }): Promise<unknown>
}
Parameters
| Param | Type | Required | Description |
|---|---|---|---|
| table | | yes | Table name |
| opts | | yes | Aggregate options (fn: count|sum|avg|min|max, column?, groupBy?) |
Examples
import { Client } from '@blueforge/client'
const bf = new Client({ apiKey: process.env.BF_API_KEY!, url: 'https://your-project.blueforge.dev' })
const result = await bf.aggregate('orders', { fn: 'sum', column: 'amount', groupBy: 'status' })
Throws
| Error | Condition |
|---|---|
| API request failed |
| Network issue |
Pitfalls
- Performance — aggregate queries scan the entire table; add
filters in the query builder for large datasetsWHERE - Type safety — the column must support the aggregate function (e.g.
on a text column fails at runtime)AVG
See also
{auto-injected}
Tested against
{auto-injected}