Getting Started

Tutorial: Building with CleaveDB

Expressions & formulas

CleaveDB's expression engine provides rich support for string manipulation, mathematical calculations, and boolean predicates, enabling sophisticated data transformations at the database kernel level.

Supported expression types

TypeOperators / FunctionsExample Expression
String JoiningCONCAT(), +CONCAT(first, " ", last)
Arithmetic+, -, *, /(celsius * 9/5) + 32
Financial MathMultiplication, Subtractionmargin AS price - cost
Boolean Predicate>=, <=, ==, !=is_adult AS age >= 18
Constant ValueLiteralsstatus AS "active"

1. String operations (CONCAT)

Combine multiple strings, field references, and delimiter literals:

CleaveQLExample · String concatenation
ENRICH users WITH full_name AS CONCAT(first, " ", last)
ENRICH addresses WITH formatted AS street + ", " + city + " " + zip

If any operand is missing or null, the expression safely handles the missing key without failing the query.

2. Numeric calculations and unit conversion

Execute mathematical formulas across multiple numeric document fields:

CleaveQLExample · Temperature conversion formula
ENRICH sensors WITH fahrenheit AS (celsius * 9/5) + 32

Calculate business metrics such as net profit margin:

CleaveQLExample · Profit margin calculation
ENRICH inventory WITH margin AS price - cost, markup_pct AS ((price - cost) / cost) * 100

The calculated properties evaluate synchronously during result projection.

3. Boolean flags and classifications

Generate dynamic boolean flags based on document field thresholds:

CleaveQLExample · Eligibility and threshold flags
-- Check adult age status
ENRICH users WITH is_adult AS age >= 18

-- Flag stock alerts
ENRICH products WITH in_stock AS quantity > 0, low_stock AS quantity <= 5

You can subsequently run indexed queries like FIND users WHERE is_adult = true.