multi-dbman-cli
v0.1.8
Published
Multi-DB manager CLI (Postgres, MySQL, MongoDB)
Maintainers
Readme
DBMAN CLI — Multi‑Database Manager CLI
dbman is a CLI tool to manage multiple databases from a single interface. It supports Postgres, MySQL, and MongoDB for connection management and adds convenient SQL helpers for common operations.
Features
Manage connections for Postgres, MySQL, MongoDB
Test connections with one command
Run arbitrary SQL (
query) on Postgres/MySQLcreate-db,drop-dbcreate-table,drop-tableselect,insert,update,delete-row
Installation
npm i -g multi-dbman-cliQuick Start (Step‑by‑Step)
1) Add a connection
dbman configFollow the prompts to name your connection and choose the DB type. Values are saved into the nearest .dbman.yaml.
2) List connections
dbman listShows all known connections (from project/user config).
┌─────────┬──────────────┬────────────┬─────────────┬──────┬────────────┬──────────────┬─────────────────────────────┬────────┐
│ (index) │ name │ type │ host │ port │ user │ database │ uri │ dbName │
├─────────┼──────────────┼────────────┼─────────────┼──────┼────────────┼──────────────┼─────────────────────────────┼────────┤
│ 0 │ 'mypg' │ 'postgres' │ 'localhost' │ 5432 │ 'postgres' │ 'appdb' │ │ │
│ 1 │ 'mymysql' │ 'mysql' │ 'localhost' │ 3306 │ 'root' │ 'appdb' │ │ │
│ 2 │ 'test-pg' │ 'postgres' │ 'localhost' │ 5432 │ 'postgres' │ 'testpg_db' │ │ │
│ 3 │ 'test-mysql' │ 'mysql' │ 'localhost' │ 3306 │ 'root' │ 'testsql_db' │ │ │
│ 4 │ 'mymongo' │ 'mongo' │ │ │ │ │ 'mongodb://localhost:27017' │ 'test' │
└─────────┴──────────────┴────────────┴─────────────┴──────┴────────────┴──────────────┴─────────────────────────────┴────────┘3) Test a connection
# Test a specific one
dbman test -d mypg✅ mymongo (mongo) OK
4) Check DB servers (doctor)
# Check all configured DB connections
dbman doctorVerify that your configured database servers are running. If a server is not reachable, doctor shows OS-specific installation and startup instructions. Works for Postgres, MySQL, and MongoDB.
| Connection | Type | Status | Details / Fix |
|-------------|-----------|---------|---------------|
| mypg | postgres | ❌ | Cannot connect to postgres at localhost:5432. Run: sudo apt update && sudo apt install postgresql && sudo systemctl start postgresql |
| mymysql | mysql | ✅ | mysql is running at localhost:3306 |
| test-pg | postgres | ❌ | Cannot connect to postgres at localhost:5432. Run: sudo apt update && sudo apt install postgresql && sudo systemctl start postgresql |
| test-mysql | mysql | ✅ | mysql is running at localhost:3306 |
| mymongo | mongo | ✅ | MongoDB is running at mongodb://localhost:27017 |
5) Create a database (Postgres/MySQL)
You must connect to a server-level database that allows creating others (e.g.,
postgreson Postgres, or any DB on MySQL with permissions).
dbman create-db appdb -d mypg6) Create a table (Postgres/MySQL)
Provide columns as name:TYPE. The tool uppercases the type for convenience.
# Postgres example
dbman create-table users -d mypg -c "id:SERIAL PRIMARY KEY" -c "name:TEXT" -c "age:INT" -c "email:VARCHAR(255)"
# MySQL example
dbman create-table products -d mymysql -c "id:INT PRIMARY KEY AUTO_INCREMENT" -c "name:VARCHAR(255)" -c "price:DECIMAL(10,2)"7) Insert rows (Postgres/MySQL)
Provide column=value pairs. Values are inserted as strings; most RDBMS will coerce types where possible.
dbman insert users -d mypg -v "name=Alice" "age=25" "[email protected]"8) Select rows (Postgres/MySQL)
Use a simple WHERE expression (raw SQL).
# All rows
dbman select users -d mypg
# Filtered
dbman select users -d mypg -w "age >= 18"9) Update rows (Postgres/MySQL)
dbman update users -d mypg -s "age=26" -s "[email protected]" -w "name='Alice'"10) Delete rows (Postgres/MySQL)
dbman delete-row users -d mypg -w "age < 18"11) Drop a table (Postgres/MySQL)
dbman drop-table users -d mypg12) Drop a database (Postgres/MySQL)
dbman drop-db appdb -d mypg13) Run arbitrary SQL (Postgres/MySQL)
# Against the default connection
dbman query -q "SELECT * FROM users ORDER BY id DESC;"
# Against a specific connection
dbman query -d mymysql -q "SELECT COUNT(*) AS c FROM products;"
# JSON output (only for `query`)
dbman query -d mymysql -q "SELECT * FROM products LIMIT 5;" --json🐘 Postgres quick demo
dbman config # create `mypg`
dbman test -d mypg
dbman create-db appdb -d mypg
# point `mypg` at `appdb` in .dbman.yaml, then:
dbman create-table users -d mypg -c "id:SERIAL PRIMARY KEY" -c "name:TEXT" -c "age:INT" -c "email:VARCHAR(255)"
dbman insert users -d mypg -v "name=Alice" "age=25" "[email protected]"
dbman select users -d mypg -w "age >= 18"
dbman update users -d mypg -s "age=26" -w "name='Alice'"
dbman delete-row users -d mypg -w "age < 18"🐬 MySQL quick demo
dbman config # create `mymysql`
dbman test -d mymysql
dbman create-db shopdb -d mymysql
# point `mymysql` at `shopdb` in .dbman.yaml, then:
dbman create-table products -d mymysql -c "id:INT PRIMARY KEY AUTO_INCREMENT" -c "name:VARCHAR(255)" -c "price:DECIMAL(10,2)"
dbman insert products -d mymysql -v "name=Keyboard" "price=39.90"
dbman select products -d mymysql🍃 MongoDB note (DBMAN CLI)
- You can configure and test MongoDB connections using
dbman configanddbman test.
List collections
dbman mongo-list-collections -d mymongoInsert a document (creates collection if not exists)
dbman mongo-insert <collection-name> -d mymongo "name=Mg Mg" "age=25" "[email protected]"Update a document
dbman mongo-update <collection-name> -d mymongo -s "age=26" -w '{"name":"Alice"}'Find documents
dbman mongo-find <collection-name> -d mymongo -w '{"age":{"$gte":18}}'Delete a document
dbman mongo-delete <collection-name> -d mymongo -w '{"name":"Alice"}'Drop a collection
dbman mongo-drop-collection <collection-name> -d mymongo🔧 Uninstall
npm uninstall -g multi-dbman-cli