Skip to content

deepdadou/dbq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dbq 🗄️

A multi-database query CLI tool — like pgcli/mycli but supports PostgreSQL, MySQL, SQLite & MongoDB

npm version License: MIT

Features

  • 🔌 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

Install

npm install -g @mazhu/dbq

Quick Start

# 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.json

Commands

dbq connect <url>

Connect 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

dbq query <sql>

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

dbq tables

List all tables in the connected database.

dbq schema <table>

Show the structure of a specific table including columns, types, and constraints.

dbq export <sql> --format <csv|json>

Export query results to a file.

Options:

  • --format, -f — Output format: csv or json (required)
  • --output, -o — Output file path (defaults to stdout)

dbq connections

List saved connections.

dbq use <name>

Switch to a saved connection.

Configuration

Connections are saved in ~/.dbq/config.json. You can edit this file directly or use the CLI commands.

MongoDB Support

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 users

License

MIT © mazhu

About

Universal database query CLI - PostgreSQL, MySQL, SQLite, MongoDB with colorful output

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors