@alancnet/psqlite
v1.0.0
Published
Interactive sqlite3-style shell for PGlite (PostgreSQL in WASM)
Downloads
79
Maintainers
Readme
psqlite
Interactive command-line shell for PGlite—PostgreSQL compiled to WebAssembly—with a sqlite3-shaped interface: flags, one-shot SQL, piping, and dot commands.
Install
npm install -g @alancnet/psqliteThe psqlite command name is unchanged after install.
Requires Node.js 18+. PGlite is not installed by this package. Install @electric-sql/pglite in your project or globally (npm install -g @electric-sql/pglite). At runtime, psqlite loads PGlite from the nearest package.json directory when walking up from your current working directory, then from the global npm modules folder if needed.
Usage
Same overall shape as sqlite3: optional flags, then FILENAME (the PGlite data directory), then optional SQL to run once. If you omit FILENAME, PSQLITE_DATA_DIR, and -d, psqlite uses the current directory when it looks like an initialized PGlite/PostgreSQL data directory (e.g. it contains PG_VERSION—typical when your shell is cd’d into the cluster).
Start the REPL:
psqlite ./mydb
# or
PSQLITE_DATA_DIR=./data psqlite
# or
psqlite -d ./dataRun SQL and exit:
psqlite ./mydb -e "SELECT version()"
psqlite ./mydb "SELECT 1"Other common options:
psqlite --help
psqlite -version
psqlite -csv -noheader ./data "SELECT * FROM mytable LIMIT 5"
psqlite -init schema.sql ./data
psqlite --file queries.sql -d ./data
echo "SELECT 1" | psqlite -batch ./mydbEnvironment
| Variable | Meaning |
|----------|---------|
| PSQLITE_DATA_DIR | Database directory when you omit FILENAME on the command line (-d / --data-dir overrides this and FILENAME) |
Dot commands (interactive)
At the pglite> prompt: .tables, .schema, .indexes, .mode, .headers, .pretty, .databases, .quit / .exit / \q.
Developing this repo
This package does not ship @electric-sql/pglite. Install it in this directory (or run the CLI from another project that already depends on PGlite):
npm install
npm install @electric-sql/pglite
node bin/psqlite.js --helpLink globally while hacking:
npm link
psqlite -versionLicense
MIT
