Getting Started

Tutorial: Building with CleaveDB

Named Results (AS) & Multi-Metrics

By default, DISTILL names output keys after the aggregation function used (such as "total", "avg", or "count"). With the AS keyword, you can assign descriptive names to result fields and combine multiple metrics in a single comma-separated query.

Custom output aliases with AS

Append AS <alias> directly following an aggregate expression to rename its JSON output key:

CleaveQLExample · Custom count alias
DISTILL FROM staff COUNT AS headcount

Or for numeric totals:

CleaveQLExample · Custom sum alias
DISTILL FROM staff TOTAL age AS payroll_age

The database serializes the payload directly using your designated keys (e.g. {"payroll_age": 119.0}).

Combining multiple metrics in one pass

Separate multiple aggregation clauses with commas to calculate comprehensive analytical summaries simultaneously:

CleaveQLExample · Multi-metric summary pass
DISTILL FROM staff TOTAL age AS total, MIN age AS youngest, MAX age AS oldest, COUNT AS n

CleaveDB computes all four metrics concurrently in a single traversal pass through the bucket, returning:

CleaveQLExample · Result payload
{
  "total": 119.0,
  "youngest": 24,
  "oldest": 35,
  "n": 4
}

Quoting bucket names

Bucket names can be unquoted or double-quoted when adhering to strict SQL formatting styles:

CleaveQLExample · Quoted bucket identifier
DISTILL FROM "staff" COUNT

Automation with scheduled tasks (EVERY)

In production environments, DISTILL is frequently scheduled to generate recurring analytical snapshots:

CleaveQLExample · Periodic hourly distillation
EVERY 1 HOURS DO ( DISTILL FROM sales TOTAL price )