sqltree

1.4.3 · active · verified Wed Apr 22

sqltree is an interactive Terminal User Interface (TUI) client designed for seamless navigation and interaction with PostgreSQL and MySQL databases. It currently ships with version 1.4.7, with updates primarily driven by dependency bumps and feature enhancements, indicating active development. The tool differentiates itself through a two-column layout featuring a navigable tree browser for databases, schemas, and tables on one side, and a full-screen SQL REPL with auto-completion on the other. It supports paginated data browsing, result export to CSV/JSON, and persistent connection profiles, all within a unified interface for both database types. sqltree runs on Node.js 20 or higher.

Common errors

Warnings

Install

Imports

Quickstart

This Node.js script demonstrates how to programmatically launch the `sqltree` CLI tool via `npx`, connecting to a PostgreSQL database using a connection URI. It uses `child_process.spawn` to inherit the terminal's I/O, allowing the interactive TUI to function.

const { spawn } = require('child_process');

// Example: Connect to a PostgreSQL database using a URI from an environment variable.
// This demonstrates programmatically launching the sqltree CLI.
// Replace 'your_user', 'your_password', 'localhost', '5432', 'your_database_name' with actual values.
// For security, it's recommended to use environment variables for sensitive data.
const DB_URI = process.env.SQLTREE_PG_URI ?? 'postgresql://your_user:your_password@localhost:5432/your_database_name';

console.log(`Launching sqltree to connect to: ${DB_URI.replace(/:[^@]+@/, ':*****@')}`); // Mask password for logging

const child = spawn('npx', ['sqltree', '--uri', DB_URI], {
  stdio: 'inherit', // Allows sqltree's TUI to render in the current terminal
  shell: true // Required for 'npx' command to be found on some systems
});

child.on('error', (err) => {
  console.error('Failed to start sqltree process:', err);
});

child.on('close', (code) => {
  if (code !== 0) {
    console.error(`sqltree process exited with code ${code}`);
  } else {
    console.log('sqltree process exited successfully.');
  }
});

view raw JSON →