DocsData

Collections and rules

Collections are real SQLite tables, and their rules are compiled into the SQL that reads them.

A collection’s rules are part of the query that fetches its rows, not a check made afterwards. To make a collection, add it in the admin or in schema.json:

schema.json
{
  "collections": [{
    "name": "todos",
    "schema": [
      { "name": "title", "type": "text", "required": true },
      { "name": "done", "type": "bool" }
    ],
    "rules": { "list": "@request.auth.id != null" }
  }]
}

Features include:

  • Ten field types, with composite and unique indexes
  • Five rules (list, view, create, update, delete), and rules per field
  • Views: read-only collections made from a SQL SELECT
  • REST, realtime and a typed client for every collection

Fields

The field types are text, number, bool, email, url, date, json, select, relation and file. A collection can declare composite and unique indexes.

A collection with "extends": "_users" holds an app’s own profile fields, under the same id as the user.

Every record also has five fields the server sets:

FieldWhat it holds
id15 letters and digits, made with the record. Ids sort by when they were made.
created_at, updated_atWhen the record was made and last changed, in UTC (2026-10-01T14:48:54Z).
created_by, updated_byWho made it and who last changed it: a person’s id, system for a write by the server, or the migration that wrote it (migration:V2).

A collection can define created_by or updated_by itself, for example as a relation to its users. The field is then the collection’s own, and the server still fills it in when a write leaves it out.

Rules

Each collection has five rules:

schema.json
"rules": {
  "list":   "@request.auth.id != null",
  "view":   "@request.auth.id != null",
  "create": "author = @request.auth.id",
  "update": "author = @request.auth.id",
  "delete": "author = @request.auth.id || @request.auth.staff = true"
}
  • With no rule, only superusers can do it. With "", anyone can.
  • The list rule filters: callers get only the rows they may see, and totals stay right.
  • View, update and delete answer 404, not 403, so rules can’t be used to find out whether a row exists.
  • After a write, Sluurp checks the row again inside the transaction. A write that would put a row out of the writer’s own reach is rolled back.

Fields can have their own rules too, such as who may read a salary or change a status. Sluurp enforces them in the same SQL. See Rules.

Use the API

Every collection has a REST API:

GET    /api/collections/todos/records?filter=done=false&sort=-created_at
POST   /api/collections/todos/records
PATCH  /api/collections/todos/records/:id
DELETE /api/collections/todos/records/:id

// server-sent events, filtered by your rules
GET    /api/realtime?subscribe=todos

In the browser, use the client:

app.ts
import { Sluurp } from "@sluurp/client";
const sluurp = new Sluurp();
await sluurp.collection("todos").create({ title: "Milk", author: sluurp.authStore.record.id });
const open = await sluurp.collection("todos").list({ filter: "done = false" });

Sluurp parses filters and compiles them to SQL with bound parameters. It refuses a filter that names an unknown field before it builds any SQL.

Views

A view collection’s rows come from a SQL SELECT, such as a report that joins or groups other collections. You read it like any collection: list, filter, sort, expand and aggregate it. Its own list and view rules decide who sees what. It can’t be written to.

schema.json
{
  "name": "order_counts",
  "type": "view",
  "query": "SELECT customer AS id, count(*) AS orders FROM orders GROUP BY customer",
  "rules": { "list": "@request.auth.staff = true", "view": "@request.auth.staff = true" }
}
  • Write collection names in the query; Sluurp maps them to their tables.
  • The query must be one SELECT that only reads, and each row needs an id.
  • Fields come from the query’s columns: numbers where the values are numbers, text otherwise. To give a field a type of your own, such as a relation that expand can follow, declare it in schema.
  • The query reads the tables directly, not through their rules. The view’s own rules apply, so write them for whoever the view is for.
  • A collection a view reads can’t be deleted while the view exists. To change a view’s query, delete the view and make it again.
  • Sync doesn’t keep a view current: a synced list of a view is its rows as they were when read.

Table names

Each collection is a SQLite table of the same name. In the SQL console, SELECT * FROM notes reads the notes collection.

  • Your collections have plain names: notes, orders.
  • Collections Sluurp manages for you start with _: _users, _superusers.
  • Sluurp’s own tables start with __: __posts, __settings, and each collection’s search index, __fts_notes.

A collection’s name can’t start with _ or sqlite_, so your names never meet Sluurp’s or SQLite’s.

Projects

Each project is its own database file, and no query spans two. An app is pinned to one project, so its functions can’t touch another app’s data.

View as Markdown