Skip to content

SQL and migrations

Run SQL over HTTPS, apply and track migrations, and read your schema as JSON, for servers, the console and agents.

Applies to EngineCloud
View as Markdown
On this page
  1. Run a query
  2. Migrations
  3. The schema as JSON

Run a query

Terminal
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"] }'
JSON
{
  "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 query give several results.
  • read_only: true runs in a read-only transaction: safe for agents with sql: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: true when it had more rows than came back; row_count counts them all.
    • The response says the row_limit applied, and row_limit_capped: 5000 when you asked for more.
  • POST /sql/v1/transaction with {"statements": [{"sql", "params", "expect"}…]} runs up to 100 statements, each with its own parameters, in one transaction and each in a savepoint. read_only and timeout_ms work as in query.
    • An error, or an expect ({rows}, {min}, {max}) that does not hold, rolls everything back and names the statement (409 expectation_failed).
  • Every statement is recorded in sypnia_data.sql_audit: who, when, a hash and the first 200 characters.

Migrations

Terminal
POST /sql/v1/migrations   { "name": "20261117_add_orders", "sql": "create table …" }
GET  /sql/v1/migrations   → the list, newest first

Each 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.

  1. Run a query
  2. Migrations
  3. The schema as JSON

    Search pages, sections and terms