A flexible database management CLI tool with persistent configuration
npm install dbmuxA flexible, modern database management CLI tool built with TypeScript and Bun. Supports multiple database systems through a driver-based architecture, with PostgreSQL as the primary implementation.
- Multi-Database Support: Easily extendable to support MySQL, SQLite, and more
- Connection Management: Save and reuse database connections with URL or field-based input
- Type-safe CLI: Built with brocli for robust argument parsing
- Persistent Config: Connections saved to ~/.dbmux/config.json
- Database Backup & Restore: Production-ready pg_dump and pg_restore with history tracking
- Database Operations: Delete databases directly from CLI with safety confirmations
- Modern Architecture: Turborepo monorepo, ESM modules, strict TypeScript
This project is organized as a Turborepo monorepo:
```
dbmux/
├── apps/
│ └── landing/ # Next.js landing page + docs
├── packages/
│ ├── cli/ # Main CLI (publishes as 'dbmux' on npm)
│ ├── types/ # @dbmux/types - shared type definitions
│ ├── utils/ # @dbmux/utils - shared utilities
│ ├── typescript-config/ # @dbmux/typescript-config
│ └── eslint-config/ # @dbmux/eslint-config
├── turbo.json # Turborepo configuration
├── package.json # Root workspace configuration
└── bun.lock # Bun lockfile
- Bun: v1.1.0 or higher (primary runtime and package manager)v22.0.0
- Node.js: or higher (for npm distribution compatibility)
- pg_dump/pg_restore: Required for backup/restore operations (PostgreSQL only)
Install dbmux with a single command - no Node.js or npm required:
`bash`
curl -fsSL https://raw.githubusercontent.com/bhagyamudgal/dbmux/main/install.sh | bash
This automatically detects your platform and installs the latest binary.
`bash`
npm install -g dbmuxor
bun add -g dbmux
Download platform-specific binaries from GitHub Releases:
| Platform | Binary |
| --------------------- | ----------------------- |
| Linux (x64) | dbmux-linux-x64 |dbmux-darwin-x64
| macOS (Intel) | |dbmux-darwin-arm64
| macOS (Apple Silicon) | |dbmux-windows-x64.exe
| Windows (x64) | |
`bash`
git clone https://github.com/bhagyamudgal/dbmux.git
cd dbmux
bun install
bun run build
bun link
`bashConnect to a database using URL
dbmux connect --url "postgresql://user:password@localhost:5432/mydb"
Commands Reference
$3
Connect to a database and optionally save the configuration.
`bash
Interactive mode (choose between URL or individual fields)
dbmux connectUsing a database URL
dbmux connect --url "postgresql://user:password@localhost:5432/mydb?ssl=true"Using individual parameters
dbmux connect --type postgresql -H localhost -p 5432 -u postgres -d myappConnect to a saved connection
dbmux connect -n my-saved-connectionTest connection without saving
dbmux connect --url "postgresql://..." --test
`| Option | Alias | Description | Default |
| ------------ | ----- | -------------------------------------- | ------------ |
|
--url | -U | Database URL | - |
| --type | | Database type (postgresql, sqlite) | postgresql |
| --name | -n | Connection name for saving/loading | auto-gen |
| --host | -H | Database host | localhost |
| --port | -p | Database port (1-65535) | 5432 |
| --user | -u | Database username | - |
| --password | -w | Database password | prompt |
| --database | -d | Database name | - |
| --ssl | | Use SSL connection | false |
| --save | | Save connection configuration | true |
| --test | | Test connection only (don't establish) | false |$3
List databases, tables, or saved connections.
`bash
List all databases
dbmux list --databasesList tables in current database
dbmux list --tablesList tables in specific schema
dbmux list --tables --schema publicList saved connections
dbmux list --connectionsUse specific connection
dbmux list --databases -n production
`| Option | Alias | Description | Default |
| --------------- | ------ | ----------------------------- | -------- |
|
--databases | --db | List all databases | - |
| --tables | -t | List tables in database | - |
| --connections | -c | List saved connections | - |
| --connection | -n | Use specific saved connection | default |
| --schema | | Schema for table listing | public |
| --database | -d | Target database | - |$3
Execute SQL queries with flexible output formats.
`bash
Execute inline query
dbmux query -q "SELECT * FROM users LIMIT 5"Execute from file
dbmux query -f queries.sqlOutput as JSON
dbmux query -q "SELECT * FROM users" --format jsonOutput as CSV
dbmux query -q "SELECT * FROM users" --format csvLimit results
dbmux query -q "SELECT * FROM logs" --limit 100Use specific connection
dbmux query -n production -q "SELECT version()"
`| Option | Alias | Description | Default |
| -------------- | ----- | ------------------------------ | ------- |
|
--sql | -q | SQL query to execute | - |
| --file | -f | Execute SQL from file | - |
| --connection | -n | Use saved connection | default |
| --database | -d | Target database | - |
| --format | | Output format (table/json/csv) | table |
| --limit | -l | Limit number of rows | - |$3
Create database backups using pg_dump. Requires
pg_dump in PATH.####
dump create - Create a Backup`bash
Interactive mode
dbmux dump createSpecify database
dbmux dump create -d myapp_productionCustom output filename
dbmux dump create -d mydb -o my-backupDifferent format
dbmux dump create -d mydb --format plainVerbose output
dbmux dump create -d mydb --verbose
`| Option | Alias | Description | Default |
| -------------- | ----- | ---------------------------------------- | -------- |
|
--database | -d | Database to dump | prompt |
| --connection | -n | Use saved connection | default |
| --format | -f | Dump format (custom/plain/directory/tar) | custom |
| --output | -o | Output filename (without extension) | auto-gen |
| --verbose | | Enable verbose output | false |####
dump delete - Delete Dump Files`bash
Interactive selection
dbmux dump deleteDelete specific file
dbmux dump delete -f backup.dumpForce delete without confirmation
dbmux dump delete -f backup.dump -F
`| Option | Alias | Description |
| --------- | ----- | ----------------------- |
|
--file | -f | Specific file to delete |
| --force | -F | Skip confirmation |####
dump history - View Dump History`bash
Show recent dumps
dbmux dump historyLimit results
dbmux dump history -l 5Output as JSON
dbmux dump history -f json
`| Option | Alias | Description | Default |
| ---------- | ----- | -------------------------- | ------- |
|
--limit | -l | Number of entries | 10 |
| --format | -f | Output format (table/json) | table |$3
Restore databases from dump files. Requires
pg_restore and psql in PATH.####
restore run - Restore a Database`bash
Interactive mode
dbmux restore runRestore to existing database
dbmux restore run -f backup.dump -d mydbCreate new database and restore
dbmux restore run -f backup.dump -d mydb_new --createDrop existing and restore
dbmux restore run -f backup.dump -d mydb --dropRestore from history
dbmux restore run --fromHistoryVerbose output
dbmux restore run -f backup.dump -d mydb --verbose
`| Option | Alias | Description | Default |
| --------------- | ----- | -------------------------------- | ------- |
|
--file | -f | Dump file to restore | prompt |
| --database | -d | Target database name | prompt |
| --connection | -n | Use saved connection | default |
| --create | -c | Create database before restoring | false |
| --drop | | Drop database before restoring | false |
| --fromHistory | -H | Select from dump history | false |
| --verbose | | Enable verbose output | false |####
restore history - View Restore History`bash
Show recent restores
dbmux restore historyLimit and format
dbmux restore history -l 5 -f json
`$3
Direct database management operations.
####
db delete - Delete a DatabaseDelete (DROP) a database from the server. Includes safety confirmations.
`bash
Interactive selection
dbmux db deleteDelete specific database
dbmux db delete -d old_databaseForce delete (skip confirmations)
dbmux db delete -d old_database -FUse specific connection
dbmux db delete -n production -d test_db
`| Option | Alias | Description |
| -------------- | ----- | ------------------------- |
|
--database | -d | Database to delete |
| --connection | -n | Use saved connection |
| --force | -F | Skip confirmation prompts |$3
Manage saved connections and configuration.
####
config add - Add Connection`bash
dbmux config add
`Interactively add a new connection (URL or individual fields).
####
config list - List Connections`bash
dbmux config list
`Display all saved connections with details.
####
config remove - Remove Connection`bash
Interactive selection
dbmux config removeRemove specific connection
dbmux config remove -n old-connection
`####
config default - Set Default`bash
dbmux config default -n production
`Set the default connection used when no connection is specified.
####
config show - Show Configuration`bash
dbmux config show
`Display the full configuration file contents.
####
config path - Show Config Path`bash
dbmux config path
`Display the path to the configuration file (
~/.dbmux/config.json).####
config rename - Rename Connection`bash
Interactive
dbmux config renameSpecify names
dbmux config rename -n old-name --newName new-name
`####
config manage - Interactive Management`bash
dbmux config manage
`Open an interactive menu for connection management.
$3
View and manage operation history.
####
history list - List History`bash
All history
dbmux history listOnly dumps
dbmux history list -t dumpOnly restores
dbmux history list -t restoreLimit and format
dbmux history list -l 10 -f json
`| Option | Alias | Description | Default |
| ---------- | ----- | ----------------------------- | ------- |
|
--type | -t | Filter by type (dump/restore) | all |
| --limit | -l | Number of entries | 10 |
| --format | -f | Output format (table/json) | table |####
history clear - Clear History`bash
Clear all history
dbmux history clearClear only dump history
dbmux history clear -t dumpClear only restore history
dbmux history clear -t restore
`$3
`bash
dbmux status
`Show the current active session and default connection.
$3
`bash
dbmux disconnect
`Clear the active connection session, reverting to the default connection.
Configuration
DBMux stores configuration in
~/.dbmux/config.json:`json
{
"connections": {
"production": {
"type": "postgresql",
"host": "db.example.com",
"port": 5432,
"user": "admin",
"database": "myapp",
"ssl": true,
"lastConnectedAt": "2024-01-15T10:30:00Z"
},
"local": {
"type": "postgresql",
"host": "localhost",
"port": 5432,
"user": "postgres",
"database": "myapp_dev",
"ssl": false
}
},
"defaultConnection": "local",
"settings": {
"logLevel": "info",
"autoConnect": false,
"queryTimeout": 30000
}
}
`Dump files are stored in
~/.dbmux/dumps/ with operation history tracked in ~/.dbmux/history.json.Development
$3
`bash
Clone repository
git clone https://github.com/bhagyamudgal/dbmux.git
cd dbmuxInstall dependencies
bun installBuild all packages
bun run buildRun CLI in development
bun run dev:cli -- --help
`$3
`bash
Build
bun run build # Build all packages
bun run build:cli # Build CLI only
bun run build:landing # Build landing page only
bun run build:binaries # Build cross-platform binariesDevelopment
bun run dev # Start all in dev mode
bun run dev:cli # CLI development (run once)
bun run dev:cli:watch # CLI development (watch mode)
bun run dev:landing # Landing page developmentTesting
bun run test # Run all tests
bun run test:cli # CLI tests onlyCode Quality
bun run lint # Lint all packages
bun run typecheck # TypeScript check
bun run format # Format code
bun run format:check # Check formatting
`$3
Tests use Vitest with complete isolation:
`bash
Run tests
bun run testWatch mode
cd packages/cli && bun run test:watchCoverage
cd packages/cli && bun run coverage
`$3
`
packages/cli/
├── src/
│ ├── commands/ # Command implementations
│ │ ├── config/ # Config subcommands
│ │ │ ├── add.ts
│ │ │ ├── default.ts
│ │ │ ├── list.ts
│ │ │ ├── manage.ts
│ │ │ ├── path.ts
│ │ │ ├── remove.ts
│ │ │ ├── rename.ts
│ │ │ └── show.ts
│ │ ├── db/ # Database subcommands
│ │ │ └── delete.ts
│ │ ├── history/ # History subcommands
│ │ │ ├── clear.ts
│ │ │ └── list.ts
│ │ ├── config.ts
│ │ ├── connect.ts
│ │ ├── db.ts
│ │ ├── disconnect.ts
│ │ ├── dump.ts
│ │ ├── dump-delete.ts
│ │ ├── history.ts
│ │ ├── list.ts
│ │ ├── query.ts
│ │ ├── restore.ts
│ │ └── status.ts
│ ├── db-drivers/ # Database drivers
│ │ ├── database-driver.ts # Driver interface
│ │ ├── driver-factory.ts # Driver factory
│ │ └── postgres-driver.ts # PostgreSQL implementation
│ ├── utils/ # Utilities
│ │ ├── command-check.ts
│ │ ├── command-runner.ts
│ │ ├── config.ts
│ │ ├── database.ts
│ │ ├── dump-restore.ts
│ │ ├── logger.ts
│ │ ├── prompt.ts
│ │ └── session.ts
│ └── index.ts # CLI entry point
├── tests/ # Test files
├── package.json
└── tsconfig.json
`Architecture
DBMux uses a driver-based architecture for database operations:
-
DatabaseDriver Interface: Contract for all database operations
- Driver Implementations: Database-specific logic (PostgreSQL, SQLite, etc.)
- Driver Factory: Instantiates the correct driver based on connection type$3
1. Create driver:
packages/cli/src/db-drivers/mysql-driver.ts
2. Implement DatabaseDriver interface
3. Register in driver-factory.ts
4. Add type to @dbmux/typesDependencies
Runtime:
-
@drizzle-team/brocli - CLI framework
- pg - PostgreSQL client
- cli-table3 - Table formatting
- @inquirer/prompts - Interactive prompts
- chalk - Colored output
- command-exists - External command checkingDevelopment:
-
typescript - Type safety
- vitest - Testing framework
- eslint + typescript-eslint - Linting
- prettier - Code formatting
- turbo - Monorepo build systemContributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Run tests:
bun run test`