Skip to main content

Cheat Sheet

Everything in one place.

Query basics

PatternExampleResult shape
db.tableshop.customersarray of rows
db.table{a, b}shop.customers{id, name}array with only those keys
db.table[col = "x"]shop.orders[status = "paid"]filtered array
db.table[0:10]shop.orders[0:10]first 10 rows
db.table[5]shop.orders[5]single row object
db.table._desc(col)shop.orders._desc(placed_at)sorted array
db.table._count()shop.orders._count()scalar number
db.table.relationshop.customers.orderswalk to related rows
db.table{relation{a}}shop.customers{orders{total}}embed relation

Shape rules

  • Projection {…} is always last — nothing at the same level after it.
  • Filters […], slices [a:b], and aggregates _fn(…) chain in any order, any number.
  • Scalar aggregates (_count, _sum, _avg, _min, _max) end the query and return a value; no {…} needed.

Comparison operators

OpMeaning
= ==Equal
!=Not equal
< <=Less than
> >=Greater than
andLogical AND
orLogical OR

Arithmetic

OpExampleResult
+shop.orders._count() + 547
-shop.orders._sum(total) - 1001742.50
*shop.products._count() * 284
/shop.orders._sum(total) / shop.orders._count()43.87
%shop.orders._count() % 102
**2 ** 101024

Slicing

FormMeaning
[a:b]Rows a..b-1
[:b]First b rows
[a:]From a to end
[a:b:s]With step s
[-N:]Last N rows

Aggregates

FunctionReturnsExample output
_count()number42
_sum(col)number1842.50
_avg(col)number43.87
_min(col)number9.99
_max(col)number299.00
_unique(col)array["IN","US","DE"]
_asc(col)sort
_desc(col)sort
_like(p)bool (in filter)
_date(col, fmt)parsed/formatted date

Relationship types

TypeShapeExample
otoObjectCustomer → Profile
otmArrayCustomer → Orders
mtoObjectOrder → Customer
mtmArrayProduct ↔ Categories

Request fields

FieldPurpose
protopassProtocol identifier (use "default" for the auto-generated one)
queryThe ONQL string
ctxkeyContext name (e.g. account)
ctxvaluesSubstitutions for $1, $2, ...

Context rule

"orders": {
"context": {
"customer": "shop.orders[customer_id = $1]",
"admin": "shop.orders"
}
}