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:
-- 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:
-- 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:
| Format | Example | Description |
|---|---|---|
| Relative Keyword | AS OF yesterday | Evaluates to 24 hours prior to current system clock |
| Relative Interval | AS OF "2 hours ago" | Subtracts the specified duration (minutes, hours, days) |
| ISO Datetime | AS OF "2026-10-05 14:30" | Pinpoints exact calendar date and hour |
| UNIX Epoch | AS OF "1791191933" | Microsecond-level timestamp integer string |
Historical graph walk (FOLLOW ... AS OF)
Combine depth traversals with historical timestamps to retrace entire graph neighbourhoods:
FOLLOW "users:alice" THROUGH "friend" AS OF yesterday DEPTH 2This query traverses 2 hops outward from Alice, traversing only bonds that were active 24 hours ago.
