Databases and tables
A database is one SQLite file. An account can hold as many databases as its plan allows, and each database can hold as many tables as the plan allows. See Plans and limits.
Databases
List databases
curl https://api.vaultdb.io/api/databases \
-H "Authorization: Bearer $VAULTDB_API_KEY"
Returns { "databases": [...], "count": n }. Each database includes its name, display_name, branched_from (the source database, for a branch), created_at, and live table_count and row_count.
Create a database
curl -X POST https://api.vaultdb.io/api/databases \
-H "Authorization: Bearer $VAULTDB_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "dbid": "shop", "display_name": "Shop" }'
| Field | Required | Description |
|---|---|---|
dbid |
Yes | The database name. Lowercase letters, digits and dashes; starts and ends with a letter or digit; at most 100 characters. You use it in every URL. |
display_name |
No | A label for the admin app. |
Returns 201 with { "id", "dbid", "display_name", "message" }. Returns 409 if the account already has a database with that name, and 403 if the account is at its plan's database limit or your email address is not confirmed yet. With an API key, the key's creator must have confirmed their address.
Get one database
curl https://api.vaultdb.io/api/databases/shop \
-H "Authorization: Bearer $VAULTDB_API_KEY"
Returns the database with a tables array of table names.
Delete a database
curl -X DELETE https://api.vaultdb.io/api/databases/shop \
-H "Authorization: Bearer $VAULTDB_API_KEY"
This deletes the database file and the database's row-level policies, webhooks and scheduled queries. It cannot be undone. Branches taken from the database are separate databases and are not deleted.
Tables
Table and column names use letters, digits and underscores only, up to 64 characters.
List tables
curl https://api.vaultdb.io/api/databases/shop/tables \
-H "Authorization: Bearer $VAULTDB_API_KEY"
Returns { "tables": ["products", ...] }.
Create a table
curl -X POST https://api.vaultdb.io/api/databases/shop/tables \
-H "Authorization: Bearer $VAULTDB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "orders",
"columns": [
{ "name": "id", "type": "INTEGER", "primaryKey": true },
{ "name": "customer", "type": "TEXT", "notNull": true },
{ "name": "total", "type": "REAL", "default": 0 },
{ "name": "created_at", "type": "DATETIME", "default": "CURRENT_TIMESTAMP" }
]
}'
columns needs at least one column. Each column takes:
| Field | Required | Description |
|---|---|---|
name |
Yes | Letters, digits and underscores, up to 64 characters. |
type |
Yes | One of INTEGER, TEXT, REAL, BLOB, NUMERIC, DATETIME, TIMESTAMP. |
primaryKey |
No | true makes the column the primary key. An INTEGER primary key is filled in automatically when you insert a row without it. |
unique |
No | true adds a UNIQUE constraint. |
notNull |
No | true adds a NOT NULL constraint. |
default |
No | A string or number. The string CURRENT_TIMESTAMP stores the time of the insert. |
Returns 201. Returns 409 if the table exists, and 403 if the database is at its plan's table limit.
The API has no endpoint to change an existing table's columns, and raw SQL does not accept CREATE, ALTER or DROP statements. To change a table's shape, create a new table with the columns you want.
Read a table's columns
curl https://api.vaultdb.io/api/databases/shop/tables/orders/schema \
-H "Authorization: Bearer $VAULTDB_API_KEY"
Returns { "table", "schema": [...] }. Each column has SQLite's cid, name, type, notnull, dflt_value and pk fields.
Drop a table
curl -X DELETE https://api.vaultdb.io/api/databases/shop/tables/orders \
-H "Authorization: Bearer $VAULTDB_API_KEY"
This deletes the table, all its rows and its row-level policies. It is also the way to empty a table: the row API refuses a delete without a filter.