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.
Option Description Default --db <name>SQLite database name within the current space default--params <json>JSON array of bind parameters for ? placeholders None
List rows
Bind params
Named database
JSON output
$ tc sql query "SELECT id, body FROM notes ORDER BY id"
id body
1 ship docs
2 test help
2 rows returned
$ tc sql query "SELECT * FROM notes WHERE id = ?" --params '[1]'
id body
1 ship docs
1 row returned
$ tc sql query "SELECT type, count(*) AS total FROM events GROUP BY type" --db analytics
type total
signup 42
view 319
$ tc sql query "SELECT id, body FROM notes" --json
{
"columns" : [ "id" , "body"],
"rows" : [[1, "ship docs"]],
"rowCount" : 1
}
tc sql execute
Run a write or schema statement such as CREATE TABLE, INSERT, UPDATE, DELETE, or DROP TABLE.
Option Description Default --db <name>SQLite database name within the current space default--params <json>JSON array of bind parameters for ? placeholders None
Create table
Insert row
Update row
$ tc sql execute "CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY, body TEXT)"
{
"changes" : 0,
"lastInsertRowId" : null
}
$ tc sql execute "INSERT INTO notes (body) VALUES (?)" --params '["ship docs"]'
{
"changes" : 1,
"lastInsertRowId" : 1
}
$ tc sql execute "UPDATE notes SET body = ? WHERE id = ?" --params '["test help", 1]'
{
"changes" : 1,
"lastInsertRowId" : null
}
tc sql export
Download the raw SQLite database file.
Option Description Default --db <name>SQLite database name within the current space default-o, --output <file>Output file path export.db
Default database
Named database
$ tc sql export
{
"file" : "/Users/alice/project/export.db",
"size" : 16384,
"sizeHuman" : "16 KB"
}
$ tc sql export --db analytics --output analytics.db
{
"file" : "/Users/alice/project/analytics.db",
"size" : 32768,
"sizeHuman" : "32 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.
Default app database
Analytics database
Query analytics
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'