Skip to content
VaultDBDocs

CSV import and export

Import a table from CSV

POST /api/databases/{dbid}/tables/{table}/import loads rows from CSV. It needs the Databases.edit permission.

Send the CSV as the request body with Content-Type: text/csv:

curl -X POST https://api.vaultdb.io/api/databases/shop/tables/customers/import \
  -H "Authorization: Bearer $VAULTDB_API_KEY" \
  -H "Content-Type: text/csv" \
  --data-binary @customers.csv

Or send it as JSON, in a csv field:

curl -X POST https://api.vaultdb.io/api/databases/shop/tables/customers/import \
  -H "Authorization: Bearer $VAULTDB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "csv": "name,email\nAda,ada@example.com\nGrace,grace@example.com" }'

Use --data-binary rather than -d for a file, so curl keeps its line breaks.

A CSV body may be up to 20 MB. A larger one is refused with 413; split the file and import the parts. Blank lines are skipped.

Returns 201:

{ "message": "Imported 2 rows", "imported": 2, "tableCreated": true, "lastRowId": 2, "changes": 2 }

The CSV format

  • The first row is the header. Each header becomes a column name, so it must use letters, digits and underscores only, and headers must be unique.
  • Values are separated by commas. A value that contains a comma, a double quote or a line break goes in double quotes, with any double quote inside it doubled ("say ""hi""").
  • Blank lines are skipped.
  • A row with fewer values than the header is padded with empty strings. Extra values past the last header are dropped.
  • The file needs at least one data row.

If the table does not exist

The import creates it, with one TEXT column per header. Creating a table counts toward your plan's tables per database. To get other column types, create the table first, then import into it. Every value is sent as text, and SQLite converts it to the column's type where it can.

Limits

An import is one insert of many rows, so it follows the same rules as a bulk insert:

  • it can hold at most your plan's rows per bulk insert (100 on Free, 1,000 on Starter, 10,000 on Pro, 50,000 on Business),
  • it is refused if your account is at its storage limit or the table would pass your plan's rows per table,
  • every row must satisfy the table's row-level insert policies,
  • it runs in one transaction: either every row is imported or none is.

To load a larger file, split it into several imports.

An import sends one webhook and realtime insert event for the whole file, with data set to { "count": n, "source": "csv-import" }.

Export a table

GET /api/databases/{dbid}/tables/{table}/export downloads every row of a table. It needs the Databases permission.

curl -o orders.csv "https://api.vaultdb.io/api/databases/shop/tables/orders/export?format=csv" \
  -H "Authorization: Bearer $VAULTDB_API_KEY"

curl -o orders.json "https://api.vaultdb.io/api/databases/shop/tables/orders/export?format=json" \
  -H "Authorization: Bearer $VAULTDB_API_KEY"

format is csv (the default) or json. The response is a file download named <dbid>_<table>.<format>.

  • CSV: a header row of column names, then one line per row. An empty table gives an empty file.
  • JSON: one array of row objects.

Rows come in the order they were stored. The export is streamed, so the download starts at once even for a large table.

Export applies the table's select row-level policies: it returns only the rows a read would.