🌳 sqltree

An interactive terminal database client for PostgreSQL, MySQL, and 20+ compatible databases.

npm version License: MIT Node.js

1. Prerequisites

That's it β€” sqltree has no native dependencies and works on macOS, Linux, and Windows.

2. Installation

Zero-install (recommended)

Run directly with npx β€” nothing to install:

npx sqltree

Global install

If you use sqltree often, install it globally:

npm install -g sqltree
sqltree

3. Connecting to a Database

Interactive mode

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.

Terminal
$ npx sqltree

  ╔══════════════════════════════════════╗
  β•‘   🌳 sqltree v1.4.6                  β•‘
  β•‘   PostgreSQL Β· MySQL Β· CLI Client    β•‘
  β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

? Select a database type:
  ❯ PostgreSQL
    MySQL
    CockroachDB
    Redshift
    YugabyteDB
    ...

URI string

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

Individual parameters

npx sqltree -t postgres -H localhost -p 5432 -U postgres -d mydb

Environment variable

Set DATABASE_URL and sqltree picks it up automatically:

export DATABASE_URL=postgresql://user:pass@localhost/mydb
npx sqltree
sqltree supports 30+ connection aliases including CockroachDB, Redshift, TimescaleDB, Supabase, Neon, AlloyDB, Aurora, MariaDB, TiDB, SingleStore, PlanetScale, Vitess, Percona, Greenplum, Citus, CrateDB, QuestDB, Materialize, ClickHouse, and more.

4. Navigating the Tree

After connecting, sqltree displays a two-column TUI: a tree browser on the left and a detail panel on the right.

sqltree
 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
KeyAction
↑ / kMove up
↓ / jMove down
Enter / β†’ / lExpand node or browse table data
← / hCollapse node or go to parent
Tab / sEnter SQL REPL
dDescribe table structure
eExport last result
rRefresh tree
qQuit

5. Browsing Table Data

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.

sqltree β€” browsing users
β”Œβ”€ πŸ“‹ 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.

Change the rows-per-page with --page-size: npx sqltree --page-size 100 --uri ...

6. Using the SQL REPL

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.

sqltree β€” SQL REPL
 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> 

REPL commands

CommandAction
\backReturn to tree browser
\export csvExport last result as CSV
\export jsonExport last result as JSON
\export sqlExport last result as INSERT statements
\export mdExport last result as Markdown table
\save <name>Save current connection profile
Ctrl+CCancel / return to tree

7. Exporting Results

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:

FormatExtensionDescription
CSV.csvComma-separated, quoted fields
SQL.sqlINSERT INTO statements
Markdown.mdGitHub-flavored Markdown table
JSON.jsonArray of row objects

8. Dump & Restore

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).

Dump

sql> \dump
βœ” Dumped database to dump_mydb_2026-04-10.sql

sql> \dump backup.sql
βœ” Dumped database to backup.sql

Restore

sql> \restore backup.sql
βœ” Restored from backup.sql
Dump and restore require pg_dump/psql (for PostgreSQL) or mysqldump/mysql (for MySQL) to be installed and available in your PATH.

9. Saved Connections

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).

Profiles contain passwords in plain text. Treat ~/.sqltree/connections.json as sensitive β€” never commit it to version control.

10. Config File

Create ~/.sqltree/config.json to set default preferences. CLI flags override config values.

{
  "pageSize": 100,
  "ascii": false,
  "timeout": 15000,
  "ssl": true,
  "keyBindings": {}
}
KeyDefaultDescription
pageSize25Rows per page when browsing tables
asciifalseUse ASCII characters instead of emoji
timeout10000Connection timeout in milliseconds
sslfalseEnable SSL for connections
keyBindings{}Custom key binding overrides (see below)

11. Custom Key Bindings

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"]
  }
}
Only override what you need β€” unspecified actions keep their defaults.

12. Tips & Tricks

ASCII mode for CI or minimal terminals

npx sqltree --ascii --uri postgresql://...

Replaces all emoji with plain text symbols β€” useful for CI logs, SSH sessions, or terminals without Unicode support.

SSL connections

# Enable SSL
npx sqltree --ssl --uri postgresql://...

# Skip certificate verification (self-signed certs)
npx sqltree --ssl --ssl-reject-unauthorized false --uri postgresql://...

Connection timeout

# Set a 30-second timeout
npx sqltree --timeout 30000 --uri postgresql://...

Large tables

Increase page size for fewer round-trips when browsing large tables:

npx sqltree --page-size 500 --uri postgresql://...

Custom adapters

Register your own database adapter programmatically:

import { registerAdapter } from 'sqltree/adapters';
import { MyCustomAdapter } from './my-adapter.js';

registerAdapter('mydb', MyCustomAdapter);

Supported database aliases

ProtocolAliases
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