JSON document storage with secondary indexes and SQL-like WHERE queries
Kora’s document layer transforms the cache engine into a JSON-native document database. Documents are stored in a compact binary format and queried through a WHERE expression parser with automatic index optimization.
# Insert a JSON documentDOC.SET users alice '{"name":"Alice","age":30,"city":"NYC"}'# Update returns 1 if created, 0 if updated# => 1# Replace with new documentDOC.SET users alice '{"name":"Alice Smith","age":31,"city":"LA"}'# => 0
# Get full documentDOC.GET users alice# => {"name":"Alice","age":30,"city":"NYC"}# Get with field projectionDOC.GET users alice FIELDS name city# => {"name":"Alice","city":"NYC"}# Batch getDOC.MGET users alice bob charlie
pub enum DocMutation { /// Set a field path to a JSON value Set { path: String, value: Value }, /// Delete one field path Del { path: String }, /// Increment a numeric field by delta Incr { path: String, delta: f64 }, /// Append value to an array field Push { path: String, value: Value }, /// Remove matching items from array Pull { path: String, value: Value },}
# Update specific fieldsDOC.UPDATE users alice \ SET age 31 \ SET city "Boston" \ INCR login_count 1 \ PUSH tags "premium"# Delete a fieldDOC.UPDATE users alice DEL temporary_flag# Array operationsDOC.UPDATE users alice PUSH interests "rust"DOC.UPDATE users alice PULL interests "java"
# Hash index for equality lookupsDOC.CREATEINDEX users email hash# Sorted index for range queriesDOC.CREATEINDEX users age sorted# Array index for array fieldsDOC.CREATEINDEX users tags array# Unique constraintDOC.CREATEINDEX users username unique
Unique indexes are checked before writes. If a duplicate value exists, the write fails with a UniqueViolation error.
# AND conditionDOC.FIND users WHERE "age >= 25 AND city = 'NYC'"# OR conditionDOC.FIND users WHERE "city = 'NYC' OR city = 'LA'"# NOT conditionDOC.FIND users WHERE "NOT (age < 18)"# Nested logicDOC.FIND users WHERE "(age >= 30 AND city = 'NYC') OR status = 'premium'"
# Check if array contains valueDOC.FIND users WHERE "tags CONTAINS 'rust'"# Multiple conditionsDOC.FIND users WHERE "tags CONTAINS 'rust' AND age >= 25"
# Field projectionDOC.FIND users WHERE "age >= 30" PROJECT name email# Limit resultsDOC.FIND users WHERE "city = 'NYC'" LIMIT 10# Offset and limit (pagination)DOC.FIND users WHERE "active = true" LIMIT 20 OFFSET 40# Order by fieldDOC.FIND users WHERE "age >= 18" ORDER BY age ASCDOC.FIND users WHERE "city = 'NYC'" ORDER BY created_at DESC# CombinedDOC.FIND users \ WHERE "age >= 25" \ ORDER BY name ASC \ PROJECT name email \ LIMIT 10 OFFSET 0