Skip to content

Server

Terminal window
npm install -g @petradb/server
Terminal window
petradb-server [OPTIONS] [path]

If a path is given, the server opens (or creates) a persistent database at that location. Without a path, an in-memory database is used.

OptionDescription
-m, --memoryUse an in-memory database
-p, --portPort number (default: 5480)
-h, --hostHost address (default: 127.0.0.1)
-c, --configPath to a TOML configuration file
Terminal window
# In-memory database on the default port
petradb-server
# Persistent database on a custom port
petradb-server -p 8080 mydata.db
# With a config file
petradb-server -c petradb.toml mydata.db

A TOML file controls authentication, CORS, and session limits.

auth = "basic"
[[users]]
username = "admin"
password = "$HASHED_PASSWORD"
[[users]]
username = "reader"
password = "$HASHED_PASSWORD"
[cors]
origin = "*" # "*" (default), "none", or a specific origin
[sessions]
max_sessions = 100 # 0 = unlimited (default)
ModeDescription
"none"No authentication (default when no config file is given)
"basic"HTTP Basic authentication against the [[users]] list

Passwords in the config file are stored as PBKDF2 hashes.

When auth = "basic", every request (except GET /health) must include an Authorization: Basic <credentials> header.

origin valueBehaviour
"*" (default)Allow all origins
"none"No CORS headers
A URL (e.g. "https://app.example.com")Allow only that origin

All SQL requests and responses use the PetraDB binary codec (application/octet-stream). Use the @petradb/client library instead of calling these endpoints directly.

POST /sql
Content-Type: application/octet-stream
X-Session-Id: <session-id> (optional)
<sql text>

Returns a binary-encoded Seq[Result]. Without an X-Session-Id header, each request runs in a one-off transient session.

POST /session

Returns { "sessionId": "<id>" }. Use the returned ID in subsequent X-Session-Id headers to share transaction state across requests.

DELETE /session/<id>

Returns { "ok": "true" } on success, or 404 if the session does not exist.

GET /health

Returns { "status": "ok" }. Not subject to authentication.

StatusMeaning
400SQL parse error, type error, or undefined reference
401Missing or invalid credentials
409Schema or constraint violation
503Session limit reached