Skip to content

Query Schema

Complete reference for database queries.

Query Object

typescript
interface Query {
  table: string;
  operation: 'select' | 'insert' | 'update' | 'upsert' | 'delete';
  select?: string;
  data?: Record<string, any>;
  filters?: Filter[];
  order?: OrderConfig;
  limit?: number | string;
  offset?: number | string;
  single?: boolean;
  upsertOptions?: UpsertOptions;
}

Properties

table

Database table name.

json
"users"

operation

Database operation type.

OperationDescription
selectRead records
insertCreate record
updateUpdate records
upsertInsert or update
deleteDelete records

select

Columns to return.

json
"*"
"id, name, email"
"*, users(id, name)"

data

Data for insert/update/upsert.

json
{
  "name": "&#123;&#123;body.name&#125;&#125;",
  "email": "&#123;&#123;body.email&#125;&#125;",
  "user_id": "&#123;&#123;auth.sub&#125;&#125;"
}

filters

Array of filter conditions.

typescript
interface Filter {
  column: string;
  operator: FilterOperator;
  value: any;
}

See Filter Operators.

order

Sort configuration.

typescript
interface OrderConfig {
  column: string;
  ascending: boolean;
}

limit / offset

Pagination values. Can be static or dynamic.

json
{
  "limit": 10,
  "offset": 0
}

Dynamic:

json
{
  "limit": "&#123;&#123;query.limit&#125;&#125;",
  "offset": "&#123;&#123;query.offset&#125;&#125;"
}

single

Return single object instead of array.

json
true | false

upsertOptions

Conflict resolution for upsert.

typescript
interface UpsertOptions {
  onConflict: string;        // Column(s) for conflict detection
  ignoreDuplicates?: boolean;
}

Examples

Select All

json
{
  "table": "users",
  "operation": "select",
  "select": "*"
}

Select with Relations

json
{
  "table": "posts",
  "operation": "select",
  "select": "*, users(id, name, avatar)"
}

Select with Filters

json
{
  "table": "users",
  "operation": "select",
  "select": "id, name, email",
  "filters": [
    { "column": "status", "operator": "eq", "value": "active" },
    { "column": "created_at", "operator": "gte", "value": "2024-01-01" }
  ],
  "order": { "column": "created_at", "ascending": false },
  "limit": 10
}

Insert

json
{
  "table": "posts",
  "operation": "insert",
  "data": {
    "title": "&#123;&#123;body.title&#125;&#125;",
    "content": "&#123;&#123;body.content&#125;&#125;",
    "user_id": "&#123;&#123;auth.sub&#125;&#125;"
  },
  "select": "*",
  "single": true
}

Update

json
{
  "table": "posts",
  "operation": "update",
  "data": {
    "title": "&#123;&#123;body.title&#125;&#125;",
    "updated_at": "now()"
  },
  "filters": [
    { "column": "id", "operator": "eq", "value": "&#123;&#123;params.id&#125;&#125;" }
  ],
  "select": "*",
  "single": true
}

Upsert

json
{
  "table": "user_settings",
  "operation": "upsert",
  "data": {
    "user_id": "&#123;&#123;auth.sub&#125;&#125;",
    "theme": "&#123;&#123;body.theme&#125;&#125;",
    "notifications": "&#123;&#123;body.notifications&#125;&#125;"
  },
  "upsertOptions": {
    "onConflict": "user_id"
  },
  "select": "*",
  "single": true
}

Delete

json
{
  "table": "posts",
  "operation": "delete",
  "filters": [
    { "column": "id", "operator": "eq", "value": "&#123;&#123;params.id&#125;&#125;" },
    { "column": "user_id", "operator": "eq", "value": "&#123;&#123;auth.sub&#125;&#125;" }
  ]
}

Released under the ISC License.