An interactive terminal database client for PostgreSQL, MySQL, and 20+ compatible databases.
nvm install 20That's it β sqltree has no native dependencies and works on macOS, Linux, and Windows.
Run directly with npx β nothing to install:
npx sqltree
If you use sqltree often, install it globally:
npm install -g sqltree
sqltree
Just run npx sqltree with no arguments. You'll be guided through choosing a
database type, entering your host, port, user, password, and database name.
$ npx sqltree
ββββββββββββββββββββββββββββββββββββββββ
β π³ sqltree v1.4.6 β
β PostgreSQL Β· MySQL Β· CLI Client β
ββββββββββββββββββββββββββββββββββββββββ
? Select a database type:
β― PostgreSQL
MySQL
CockroachDB
Redshift
YugabyteDB
...
Pass a connection URI directly:
# PostgreSQL
npx sqltree --uri postgresql://user:pass@localhost:5432/mydb
# MySQL
npx sqltree --uri mysql://root:secret@127.0.0.1:3306/app
npx sqltree -t postgres -H localhost -p 5432 -U postgres -d mydb
Set DATABASE_URL and sqltree picks it up automatically:
export DATABASE_URL=postgresql://user:pass@localhost/mydb
npx sqltree
After connecting, sqltree displays a two-column TUI: a tree browser on the left and a detail panel on the right.
sqltree β postgres@localhost:5432 Connected
ββ π³ Browser βββββββ Detail βββββββββββββββββββββββ
β βΌ π¦ mydb ββ Database: mydb β
β βΌ π public ββ Owner: postgres β
β βΈ π users ββ Encoding: UTF8 β
β βΈ π orders ββ Size: 24 MB β
β βΈ π items ββ Tables: 3 β
β βΈ π pg_catalogββ β
β βΈ π¦ template0 ββ β
β βΈ π¦ template1 ββ β
β ββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββ navigate β β expand β β back β Tab REPL β q quit
| Key | Action |
|---|---|
β / k | Move up |
β / j | Move down |
Enter / β / l | Expand node or browse table data |
β / h | Collapse node or go to parent |
Tab / s | Enter SQL REPL |
d | Describe table structure |
e | Export last result |
r | Refresh tree |
q | Quit |
Press Enter on any table node to browse its rows. Data is paginated β use β/β to page through results and w/s to scroll within a page.
ββ π users (page 1 of 4) ββββββββββββββββββββββββββ
β id β name β email β active β
βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 1 β Alice Johnson β alice@example.com β true β
β 2 β Bob Smith β bob@example.com β true β
β 3 β Carol White β carol@example.com β false β
β 4 β Dan Lee β dan@example.com β true β
β .. β .. β .. β .. β
βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β next page β β prev page β β exit β w/s scroll
Press β to exit browse mode and return to the tree.
--page-size:
npx sqltree --page-size 100 --uri ...Press Tab to enter the full-screen SQL REPL. Type any SQL query ending with ; to execute it. Tab-completion is available for SQL keywords and table names.
SQL REPL β type a query ending with ; to execute
βββββββββββββββββββββββββββββββββββββββββββββββββββββ
sql> SELECT name, email FROM users WHERE active = true;
name β email
ββββββββββββββββββββββββββββββββββββ
Alice Johnson β alice@example.com
Bob Smith β bob@example.com
Dan Lee β dan@example.com
(3 rows)
sql>
| Command | Action |
|---|---|
\back | Return to tree browser |
\export csv | Export last result as CSV |
\export json | Export last result as JSON |
\export sql | Export last result as INSERT statements |
\export md | Export last result as Markdown table |
\save <name> | Save current connection profile |
Ctrl+C | Cancel / return to tree |
After running a query (in the REPL or by browsing a table), press e to export. You'll be prompted to choose a format:
Export format: 1) CSV 2) SQL 3) Markdown 4) JSON
> 1
β Exported to export.csv
From the REPL, use \export <format> directly:
sql> SELECT * FROM orders;
(42 rows)
sql> \export sql
β Exported to export.sql
Supported formats:
| Format | Extension | Description |
|---|---|---|
| CSV | .csv | Comma-separated, quoted fields |
| SQL | .sql | INSERT INTO statements |
| Markdown | .md | GitHub-flavored Markdown table |
| JSON | .json | Array of row objects |
In the SQL REPL, you can create full database dumps or restore from a file using the native tools (pg_dump/psql or mysqldump/mysql).
sql> \dump
β Dumped database to dump_mydb_2026-04-10.sql
sql> \dump backup.sql
β Dumped database to backup.sql
sql> \restore backup.sql
β Restored from backup.sql
pg_dump/psql (for PostgreSQL) or
mysqldump/mysql (for MySQL) to be installed and available in your PATH.Save a connection profile for quick reuse:
# In the REPL:
sql> \save production
# Next time, load it:
npx sqltree --saved
Profiles are stored in ~/.sqltree/connections.json with file permissions 0600 (owner-only read/write).
~/.sqltree/connections.json as sensitive β never commit it to version control.Create ~/.sqltree/config.json to set default preferences. CLI flags override config values.
{
"pageSize": 100,
"ascii": false,
"timeout": 15000,
"ssl": true,
"keyBindings": {}
}
| Key | Default | Description |
|---|---|---|
pageSize | 25 | Rows per page when browsing tables |
ascii | false | Use ASCII characters instead of emoji |
timeout | 10000 | Connection timeout in milliseconds |
ssl | false | Enable SSL for connections |
keyBindings | {} | Custom key binding overrides (see below) |
Override any default key binding in your config file. Each action maps to an array of keys:
{
"keyBindings": {
"quit": ["q", "C-c"],
"up": ["up", "k"],
"down": ["down", "j"],
"open": ["right", "enter", "l"],
"back": ["left", "h", "backspace"],
"repl": ["tab"],
"export": ["e"],
"refresh": ["r"],
"describe": ["d"],
"scrollUp": ["w"],
"scrollDn": ["s"]
}
}
For example, to use Vim-style splits and add Space as a REPL trigger:
{
"keyBindings": {
"repl": ["tab", "space"],
"refresh": ["r", "f5"]
}
}
npx sqltree --ascii --uri postgresql://...
Replaces all emoji with plain text symbols β useful for CI logs, SSH sessions, or terminals without Unicode support.
# Enable SSL
npx sqltree --ssl --uri postgresql://...
# Skip certificate verification (self-signed certs)
npx sqltree --ssl --ssl-reject-unauthorized false --uri postgresql://...
# Set a 30-second timeout
npx sqltree --timeout 30000 --uri postgresql://...
Increase page size for fewer round-trips when browsing large tables:
npx sqltree --page-size 500 --uri postgresql://...
Register your own database adapter programmatically:
import { registerAdapter } from 'sqltree/adapters';
import { MyCustomAdapter } from './my-adapter.js';
registerAdapter('mydb', MyCustomAdapter);
| Protocol | Aliases |
|---|---|
| PostgreSQL | postgres, postgresql, pg, cockroachdb, crdb, redshift,
yugabytedb, yugabyte, timescaledb, timescale, supabase,
neon, alloydb, aurora-pg, greenplum, gpdb,
citus, cratedb, crate, questdb, materialize, mz |
| MySQL | mysql, mariadb, tidb, singlestore, memsql,
planetscale, vitess, aurora-mysql, percona, clickhouse |