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
}
KeyTypeDescription
whereobjectOptional. Filter conditions. Omit or null = no filter.
orderByarrayOptional. Sort by one or more columns.
limitnumberOptional. Max rows (non-negative integer).
offsetnumberOptional. Skip N rows (non-negative integer).

Where clause

where can be:

  1. A single condition{ "field": "columnName", "op": "eq", "value": 42 }
  2. Logic node{ "and": [ ... ] } or { "or": [ ... ] } (arrays of conditions or nested logic).

Operators

OperatorDescriptionvalue required
eqEqualsYes (except null)
neNot equalsYes
gtGreater thanYes
gteGreater than or equalYes
ltLess thanYes
lteLess than or equalYes
containsString contains (case-insensitive)Yes
startsWithString starts with (case-insensitive)Yes
endsWithString ends with (case-insensitive)Yes
inValue in listYes (array)
notInValue not in listYes (array)
isNullValue is null/undefinedNo
isNotNullValue is not null/undefinedNo

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
}