Tutorial: Building with CleaveDB
The UPDATE Command
In addition to CHANGE, CleaveQL natively supports the UPDATE command. If you come from a relational SQL background, UPDATE offers immediate familiarity while operating directly on flexible JSON documents within CleaveDB buckets.
Direct document update
You can target a specific document by its bucket and ID:
UPDATE users "jane" SET status = "active"This updates the status property on Jane's document in place. Existing graph bonds, tenant namespaces, and untouched properties are fully preserved.
Updating multiple fields with UPDATE
Set multiple fields simultaneously with comma-separated assignments:
UPDATE users "jane" SET status = "verified", plan = "pro", updated_at = 1712750400All field updates are processed atomically through CleaveDB's Write-Ahead Log (WAL).
Conditional updates with WHERE
Use WHERE to update every document meeting specific criteria across a bucket:
UPDATE orders WHERE status = "pending" SET status = "processing"Every document satisfying the WHERE clause is updated in an atomic transaction.
Sub-queries inside UPDATE
Embed nested SCOOP queries directly within your UPDATE condition:
UPDATE orders SET status = "flagged" WHERE customer_id IN (
SCOOP users WHOSE status IS "banned" YIELD gid
)The sub-query resolves the candidate user IDs, and the outer UPDATE modifies all corresponding order records seamlessly.
