Query language
Storion uses a JSON query object to filter and sort table data. Use it with db.query(tableName, query).
Query structure
{
"where": { ... },
"orderBy": [ ... ],
"limit": 1000,
"offset": 0
}
| Key | Type | Description |
|---|---|---|
where | object | Optional. Filter conditions. Omit or null = no filter. |
orderBy | array | Optional. Sort by one or more columns. |
limit | number | Optional. Max rows (non-negative integer). |
offset | number | Optional. Skip N rows (non-negative integer). |
Where clause
where can be:
- A single condition –
{ "field": "columnName", "op": "eq", "value": 42 } - Logic node –
{ "and": [ ... ] }or{ "or": [ ... ] }(arrays of conditions or nested logic).
Operators
| Operator | Description | value required |
|---|---|---|
eq | Equals | Yes (except null) |
ne | Not equals | Yes |
gt | Greater than | Yes |
gte | Greater than or equal | Yes |
lt | Less than | Yes |
lte | Less than or equal | Yes |
contains | String contains (case-insensitive) | Yes |
startsWith | String starts with (case-insensitive) | Yes |
endsWith | String ends with (case-insensitive) | Yes |
in | Value in list | Yes (array) |
notIn | Value not in list | Yes (array) |
isNull | Value is null/undefined | No |
isNotNull | Value is not null/undefined | No |
String comparisons are case-insensitive. For json columns, comparisons use the JSON string representation.
OrderBy
Array of { "field": "columnName", "direction": "asc" | "desc" }. Multiple columns supported; earlier entries have higher priority.
Example with db.query()
const { rows, totalCount } = await db.query('users', {
where: {
and: [
{ field: 'status', op: 'eq', value: 'active' },
{ field: 'name', op: 'contains', value: 'smith' }
]
},
orderBy: [
{ field: 'created_at', direction: 'desc' },
{ field: 'id', direction: 'asc' }
],
limit: 20,
offset: 0
});
Returns { rows: [...], totalCount: number }.
Sample queries
No filter (show all rows)
{}
Single condition: name contains "foo"
{
"where": {
"field": "name",
"op": "contains",
"value": "foo"
}
}
AND: multiple conditions
{
"where": {
"and": [
{ "field": "status", "op": "eq", "value": "active" },
{ "field": "name", "op": "contains", "value": "smith" }
]
}
}
OR: status is "active" or "pending"
{
"where": {
"or": [
{ "field": "status", "op": "eq", "value": "active" },
{ "field": "status", "op": "eq", "value": "pending" }
]
}
}
In list: status in ["active", "pending", "draft"]
{
"where": {
"field": "status",
"op": "in",
"value": ["active", "pending", "draft"]
}
}
Null check: email is null
{
"where": {
"field": "email",
"op": "isNull"
}
}
Full example: filter + sort + limit/offset
{
"where": {
"and": [
{ "field": "status", "op": "eq", "value": "active" },
{ "field": "name", "op": "contains", "value": "smith" }
]
},
"orderBy": [
{ "field": "created_at", "direction": "desc" },
{ "field": "id", "direction": "asc" }
],
"limit": 100,
"offset": 0
}