Database and REST

/rest/v1: PostgREST-style reads and writes under row-level security, with filters, embedding and upserts.

Your data is Postgres. Connect with any Postgres driver, ORM or psql:

  • postgres mode: your own database URL;
  • chronos mode: postgres://app:<engine_token>@127.0.0.1:54329/main?sslmode=require (chronos.pg_listen). The password is engine_token from the data folder's secrets.json; any login name works except forkbase, the engine's own.

On top of it, /rest/v1/<table> serves the tables and views of rest.schemas over HTTP, the way PostgREST does. So supabase-js works as is:

TypeScript
import { createClient } from "@supabase/supabase-js";
const supabase = createClient("http://127.0.0.1:8000", ANON_KEY);
const { data } = await supabase.from("notes").select("id, body, tags(name)").gt("n", 1).order("n", { ascending: false });

Reads

HTTP
GET /rest/v1/notes?select=id,body,tags(name)&n=gt.1&order=n.desc&limit=20&offset=40
apikey: <anon key>
Authorization: Bearer <access token>     (when someone is signed in)
  • select: columns, *, renames (title:body), and one level of embedding along single-column foreign keys either way: tags(name), note:notes(body), rel!column(...) when two keys join the same tables.
  • order=col.asc|desc[.nullsfirst|.nullslast], several separated by commas.
  • limit, offset. A read returns at most rest.max_rows (1000).
  • Prefer: count=exact adds the total to Content-Range.
  • Accept: application/vnd.pgrst.object+json asks for exactly one row (406 otherwise).

Filters

column=operator.value:

OperatorSQL
eq, neq=, <>
gt, gte, lt, lte>, >=, <, <=
like, ilikeLIKE, ILIKE (* is %)
isIS NULL, IS TRUE, IS FALSE
inIN (...): id=in.(1,2,3)
cs, cdcontains, contained by (arrays, JSON)

not. before any operator negates it (status=not.eq.closed). Combine with or=(a.eq.1,and(b.gt.2,c.is.null)).

Writes

POST /rest/v1/notesinsert one object or an array
POST with Prefer: resolution=merge-duplicatesupsert; on_conflict=cols (default: the primary key)
PATCH /rest/v1/notes?id=eq.5update the rows the filters match
DELETE /rest/v1/notes?id=eq.5delete them

PATCH and DELETE need at least one filter, and refuse limit and offset: a mistake never touches every row. Prefer: return=representation returns the written rows.

Other schemas in rest.schemas: Accept-Profile: <schema> for reads, Content-Profile: <schema> for writes.

Schema

GET /rest/v1/ lists the served tables, their columns and keys. A table you make or change is served at once.

Who sees what

Every request runs as a role (anon, authenticated or service_role) with the caller's token claims in request.jwt.claims. A new table is closed to anon and authenticated until you grant it, and row-level security decides which rows. See Auth, row-level security.

Forkbase's own schemas (auth, storage, forkbase, agents, jobs, mcp) are never served.

Errors

JSON
{"code": "42501", "message": "permission denied for table notes", "details": null, "hint": null}

Postgres errors keep their SQLSTATE code. Request mistakes use PostgREST's PGRST... codes.

Something wrong or missing? Edit this page on GitHub or open an issue.

Database and REST · Forkbase