SQL and migrations
Run SQL over HTTPS, apply and track migrations, and read your schema as JSON, for servers, the console and agents.
On this page
Run a query
curl -X POST https://<ref>.data.sypnia.com/sql/v1/query \
-H "Authorization: Bearer syp_sk_…" -H "content-type: application/json" \
-d '{ "query": "select status, count(*) from public.orders where created_at > $1 group by 1", "params": ["2026-11-01"] }'{
"results": [
{ "command": "SELECT", "columns": [{ "name": "status", "type": "text" }, { "name": "count", "type": "int8" }],
"rows": [["paid", 412], ["pending", 37]], "row_count": 2 }
],
"duration_ms": 18
}- Several statements in one
querygive several results. read_only: trueruns in a read-only transaction: safe for agents withsql:read.- Who may call it: a secret key, a token with
sql:read/sql:write, or the project’s owner from the console. - It runs as
sypnia_admin, the owner of your schemas, not a superuser: it cannot touch other databases or the engine’s own secrets. - Limits: 15 seconds by default (up to 60 with
timeout_ms), 5 000 rows returned per result.- Each result says
truncated: truewhen it had more rows than came back;row_countcounts them all. - The response says the
row_limitapplied, androw_limit_capped: 5000when you asked for more.
- Each result says
POST /sql/v1/transactionwith{"statements": [{"sql", "params", "expect"}…]}runs up to 100 statements, each with its own parameters, in one transaction and each in a savepoint.read_onlyandtimeout_mswork as inquery.- An error, or an
expect({rows},{min},{max}) that does not hold, rolls everything back and names the statement (409 expectation_failed).
- An error, or an
- Every statement is recorded in
sypnia_data.sql_audit: who, when, a hash and the first 200 characters.
Migrations
POST /sql/v1/migrations { "name": "20261117_add_orders", "sql": "create table …" }
GET /sql/v1/migrations → the list, newest firstEach migration runs in one transaction and is recorded in sypnia_data.migrations (version, name, checksum, when, by whom). Applying the same name twice with a different checksum is refused. npx @sypnia/data migrate applies a folder of .sql files this way, in order; any other migration tool works too with a direct connection.
The schema as JSON
GET /sql/v1/schema returns every table, column, type, key, relation, policy and function of the exposed schemas. The console, npx @sypnia/data pull, ORMs’ code generators and agents all read it.