Getting Started

Tutorial: Building with CleaveDB

EVERY — repeating tasks

CleaveDB includes a built-in scheduler that executes CleaveQL commands on a repeating interval. Using the EVERY keyword, you can automate database maintenance, rollup reporting, data expirations, and background schema migrations without relying on external cron utilities.

Syntax and time intervals

The EVERY statement accepts standard time units (SECONDS, MINUTES, HOURS, or daily calendar triggers):

CleaveQLExample · General EVERY syntax
EVERY <n> SECONDS DO ( <CleaveQL command> )
EVERY <n> MINUTES DO ( <CleaveQL command> )
EVERY <n> HOURS DO ( <CleaveQL command> )
EVERY DAY AT MIDNIGHT DO ( <CleaveQL command> )

The command inside the parentheses (...) can be any valid CleaveQL query or transaction block, including reads, aggregates, mutations, or maintenance operations.

Periodic analytics and rollup reporting

Combine EVERY with DISTILL to automatically compute metrics and audit financial records on a recurring basis:

CleaveQLExample · Scheduled financial aggregation
EVERY 1 HOURS DO ( DISTILL FROM sales TOTAL price )

This query executes every hour against the storage engine, delivering freshly aggregated revenue totals without keeping long-running client connections open.

Automated garbage collection & cleanup

Safely manage temporary session records and purge recycled documents from the _rubbish bin:

CleaveQLExample · Session eviction and rubbish emptying
-- Drain expired sessions every 5 minutes
EVERY 5 MINUTES DO ( DRAIN sessions WHERE expired = true )

-- Empty the _rubbish recycling bin every night
EVERY DAY AT MIDNIGHT DO ( INCINERATE EVERYTHING FROM _rubbish )

By orchestrating DRAIN and INCINERATE at predictable intervals, system storage stays lean without manual operational overhead.

Continuous migration and graph healing

Background jobs can also run zero-downtime schema migrations or graph integrity repairs:

CleaveQLExample · Periodic migration and HEAL routine
-- Mark aging accounts as stale every 30 minutes
EVERY 30 MINUTES DO ( MIGRATE users FROM {"status":"old"} TO {"status":"stale"} )

-- Perform graph pointer healing every hour
EVERY 1 HOUR DO ( HEAL ALL )

Running HEAL ALL verifies graph forward/reverse references and rebuilds any dangling vector embedding pointers.