Getting Started

Tutorial: Building with CleaveDB

Chaining Stages

In CleaveQL, the THEN keyword links transformation stages into a coherent stream. Each stage consumes records produced by the prior stage, applies its transformation, and forwards the results onward.

Anatomy of a complete pipeline

You can chain filtering, sorting, pagination, and projection together in a single readable command:

CleaveQLExample · Four-stage processing pipeline
PIPE FROM users
  THEN WHERE age > 20
  THEN ARRANGED BY age GOING DOWN
  THEN LIMIT 3
  THEN SHOW name, age

Here is what happens during execution:

  1. PIPE FROM users: Streams records from the users bucket into the pipeline.
  2. THEN WHERE age > 20: Discards documents where age <= 20.
  3. THEN ARRANGED BY age GOING DOWN: Orders surviving records in descending order of age.
  4. THEN LIMIT 3: Halts the stream after the top 3 items are emitted.
  5. THEN SHOW name, age: Strips all internal metadata and other document fields, returning only name and age.

Immediate post-write pipelines

CleaveDB allows executing a PIPE query immediately following a write command (like POUR) on the exact same line. This lets you insert a document and immediately query the updated dataset in one atomic roundtrip:

CleaveQLExample · Insert and pipe on one line
POUR INTO emp "z1" {"name": "Zed", "age": 50, "dept": "IT"} PIPE FROM emp THEN WHERE age > 45 THEN SHOW name

This pattern is common for command-query operations where a client needs to confirm the state of the bucket right after creating a record.