Getting Started

Tutorial: Building with CleaveDB

Live computed feeds

In many real-time applications, incoming raw data must be mathematically transformed, normalized, or unit-converted before display. Rather than writing client-side math functions in every frontend application, CleaveDB pairs ENRICH with LISTEN to create live computed feeds.

Virtual enrichment on stream arrival

When an ENRICH rule is active on a bucket, any incoming POUR or CHANGE mutation evaluates the formula on the fly and broadcasts the computed fields alongside raw data:

CleaveQLExample · Define computed feed and subscribe
-- 1. Declare dynamic temperature conversion formula
ENRICH sensors WITH fahrenheit AS (celsius * 9/5) + 32

-- 2. Open real-time stream subscription
LISTEN TO sensors

The virtual field fahrenheit does not consume disk space in the primary B-tree, but is dynamically calculated by the query interpreter during broadcast dispatch.

Publishing raw data

When an IoT sensor or backend service publishes raw telemetry:

CleaveQLExample · Raw telemetry insertion
POUR INTO sensors "s1" {"celsius": 20}

Subscribed clients instantly receive the fully computed payload:

CleaveQLExample · Broadcast with computed fields
{
  "event": "POUR",
  "bucket": "sensors",
  "id": "s1",
  "data": {
    "celsius": 20,
    "fahrenheit": 68
  },
  "timestamp": 1728562500
}

The frontend directly renders 68°F without executing math routines or risking rounding discrepancies across different browser platforms.

Real-time business formulas

You can compute complex multi-field metrics such as profit margins, tax rates, or risk scores:

CleaveQLExample · Live e-commerce margin feed
-- Compute profit margin on sales events
ENRICH sales WITH margin AS price - cost, tax AS price * 0.12

-- Stream to accounting dashboards
LISTEN TO sales

Every sale logged to the database immediately pushes margin and tax to active administrative dashboards.