tinySQL CLI (tinysql)

April 24, 2026 · View on GitHub

A SQLite-compatible command-line interface for tinySQL. Accepts a database file path (or :memory:) and runs in interactive REPL mode, executes inline SQL, or dispatches named subcommands for common operations.

Build

go build -o tinysql ./cmd/tinysql

Usage

tinysql [FLAGS] <database> [SQL]
tinysql [FLAGS] <database> <subcommand> [subcommand-flags]

<database> is either a file path or :memory: for an in-memory database.

Flags

FlagDescriptionDefault
-tenantTenant namespacedefault
-modeOutput mode: column, list, csv, json, tablecolumn
-headerPrint column headerstrue
-echoEcho each SQL statement before executingfalse
-cmdExecute this SQL then exit
-batchBatch mode: suppress prompts, exit on first errorfalse
-outputWrite results to this file instead of stdout

Interactive REPL

# In-memory database
./tinysql :memory:

# File-backed database (created if it doesn't exist)
./tinysql mydb.dat

Special commands inside the REPL:

CommandDescription
.tablesList all tables
.schema [table]Show CREATE TABLE for one or all tables
.mode <mode>Change output mode
.headers on|offToggle column headers
.output <file>Redirect output to a file
.quit / .exitExit
.helpShow available commands

Inline SQL

./tinysql mydb.dat "SELECT * FROM users LIMIT 5"

Subcommands

tables — List tables

./tinysql mydb.dat tables

schema — Show table schema

./tinysql mydb.dat schema users

insert — Bulk insert from a file

./tinysql mydb.dat insert -file data.csv -table users

query — Execute a query and write to a file

./tinysql mydb.dat query -sql "SELECT * FROM users" -output results.csv -format csv

export — Export a table

./tinysql mydb.dat export -table users -output users.json -format json

Examples

# One-shot query with JSON output
./tinysql :memory: -mode json "SELECT 1 AS n, 'hello' AS greeting"

# Batch mode for scripting (exit on error)
./tinysql mydb.dat -batch -cmd "INSERT INTO log VALUES (NOW(), 'ping')"

# Pipe a SQL script
cat setup.sql | ./tinysql mydb.dat -batch

# Redirect results to a file
./tinysql mydb.dat -output report.txt "SELECT * FROM sales ORDER BY amount DESC"