A multi-database query CLI tool — like pgcli/mycli but supports PostgreSQL, MySQL, SQLite & MongoDB
- 🔌 Multi-database support — PostgreSQL, MySQL, SQLite, MongoDB
- 🎨 Colorful table output — Easy to read query results
- 📤 Export to CSV/JSON — Save query results in your preferred format
- 🔍 Schema inspection — List tables, view column details
- ⚡ Connection management — Save and switch between database connections
- 🚀 Zero-config — Just connect and query
npm install -g @mazhu/dbq# Connect to a database
dbq connect postgres://user:pass@localhost:5432/mydb
dbq connect mysql://user:pass@localhost:3306/mydb
dbq connect sqlite:///path/to/database.db
dbq connect mongodb://localhost:27017/mydb
# Run a query
dbq query "SELECT * FROM users LIMIT 10"
# List all tables
dbq tables
# View table schema
dbq schema users
# Export query results
dbq export "SELECT * FROM users" --format csv --output users.csv
dbq export "SELECT * FROM users" --format json --output users.jsonConnect to a database. The URL format depends on the database type:
| Database | URL Format |
|---|---|
| PostgreSQL | postgres://user:pass@host:port/dbname |
| MySQL | mysql://user:pass@host:port/dbname |
| SQLite | sqlite:///path/to/database.db |
| MongoDB | mongodb://host:port/dbname |
Options:
--name, -n— Save connection with a name for quick switching--save— Save connection to config for later use
Execute a SQL query and display results in a formatted table.
Options:
--limit, -l— Limit number of rows (default: 100)--no-header— Don't show column headers
List all tables in the connected database.
Show the structure of a specific table including columns, types, and constraints.
Export query results to a file.
Options:
--format, -f— Output format:csvorjson(required)--output, -o— Output file path (defaults to stdout)
List saved connections.
Switch to a saved connection.
Connections are saved in ~/.dbq/config.json. You can edit this file directly or use the CLI commands.
MongoDB uses a different query syntax. For MongoDB:
# Query with MongoDB syntax
dbq query '{"collection": "users", "filter": {"age": {"$gt": 18}}, "limit": 10}'
# List collections (equivalent to tables)
dbq tables
# View collection schema (sampled)
dbq schema usersMIT © mazhu