Getting Started

Tutorial: Building with CleaveDB

AS OF — historical reads

The AS OF clause allows you to run point-in-time queries against historical states of your database. Instead of inspecting only the current live records, you can rewind your perspective to see what documents and graph bonds looked like at any earlier moment.

Historical document queries

Append AS OF to any FIND or SCOOP statement using relative or absolute time expressions:

CleaveQLExample · Point-in-time document read
-- Read logs as they existed yesterday
FIND EVERYTHING FROM logs AS OF yesterday

-- Query documents using an exact UNIX epoch timestamp
FIND products AS OF "1690000000"

The engine consults the MVCC history ledger (_history_<bucket>) to reconstruct documents matching the exact snapshot at that timestamp.

Time-travel graph bonds

Relationships in CleaveDB evolve over time. Using AS OF with bond queries allows auditing historical connections, past org charts, or previous friend graphs:

CleaveQLExample · Historical relationship traversal
-- Inspect Alice's friends as of yesterday
FIND "friend" OF "users:alice" AS OF yesterday

-- Check access bonds as of a specific unix timestamp
FIND "manages" OF "staff:david" AS OF "1690000000"

Even if bonds were severed or changed today, the historical query reflects the graph topology that was active at that chosen moment.

Supported timestamp formats

The AS OF clause accepts versatile temporal expressions:

FormatExampleDescription
Relative KeywordAS OF yesterdayEvaluates to 24 hours prior to current system clock
Relative IntervalAS OF "2 hours ago"Subtracts the specified duration (minutes, hours, days)
ISO DatetimeAS OF "2026-10-05 14:30"Pinpoints exact calendar date and hour
UNIX EpochAS OF "1791191933"Microsecond-level timestamp integer string

Historical graph walk (FOLLOW ... AS OF)

Combine depth traversals with historical timestamps to retrace entire graph neighbourhoods:

CleaveQLExample · Depth traversal with time travel
FOLLOW "users:alice" THROUGH "friend" AS OF yesterday DEPTH 2

This query traverses 2 hops outward from Alice, traversing only bonds that were active 24 hours ago.