Skip to main content
The tc sql commands let you query, update, and export SQLite databases in your TinyCloud space. Each space can use the default database or named databases with --db.

Commands

tc sql query

Run a read-only SELECT query.
tc sql query <sql>
OptionDescriptionDefault
--db <name>SQLite database name within the current spacedefault
--params <json>JSON array of bind parameters for ? placeholdersNone
$ tc sql query "SELECT id, body FROM notes ORDER BY id"
  id  body
  1   ship docs
  2   test help

  2 rows returned

tc sql execute

Run a write or schema statement such as CREATE TABLE, INSERT, UPDATE, DELETE, or DROP TABLE.
tc sql execute <sql>
OptionDescriptionDefault
--db <name>SQLite database name within the current spacedefault
--params <json>JSON array of bind parameters for ? placeholdersNone
$ tc sql execute "CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY, body TEXT)"
{
  "changes": 0,
  "lastInsertRowId": null
}

tc sql export

Download the raw SQLite database file.
tc sql export
OptionDescriptionDefault
--db <name>SQLite database name within the current spacedefault
-o, --output <file>Output file pathexport.db
$ tc sql export
{
  "file": "/Users/alice/project/export.db",
  "size": 16384,
  "sizeHuman": "16 KB"
}

Parameter Binding

Use --params for dynamic values instead of string interpolation. The value must be a JSON array, and values bind to ? placeholders in order.
tc sql execute \
  "INSERT INTO notes (body, priority) VALUES (?, ?)" \
  --params '["ship docs", 2]'
tc sql query \
  "SELECT * FROM notes WHERE priority >= ?" \
  --params '[2]'
Quote SQL strings so your shell passes the statement as one argument. Quote JSON params with single quotes when possible so double quotes inside the JSON are preserved.

Named Databases

Use --db when an app needs separate SQLite databases within the same space.
tc sql execute "CREATE TABLE notes (id INTEGER PRIMARY KEY, body TEXT)"

Scripting

Add --json for stable machine-readable output, or pipe output to another command.
tc sql query "SELECT id, body FROM notes" --json | jq '.rows[]'
tc sql execute "DELETE FROM notes WHERE id = ?" --params '[1]' --json | jq '.changes'