A command-line interface tool for managing PostgreSQL databases with a focus on simplicity, security, and user experience. Features interactive prompts, beautiful terminal output, secure credential storage, and multi-connection management.
A JavaScript CLI tool that helps you configure multiple database connections and create new databases with ease.
- π§ Interactive configuration system
- ποΈ PostgreSQL database management
- π Multiple named connections - manage different database environments
- π― Default connection support for streamlined workflows
- ποΈ Configurable database names with defaults
- π¨ Beautiful terminal output with colors and boxes
- π Secure password storage using system keychain
- πΎ Connection string generation
- π List and manage all saved connections
- PostgreSQL server installed and running
- Node.js 16.x or higher
- npm or yarn package manager
- sudo access (for global installation)
- System keychain (recommended for enhanced security):
- Linux:
libsecretandgnome-keyring(sudo apt-get install gnome-keyringon Ubuntu/Debian) - macOS: Keychain Access (built-in)
- Windows: Credential Manager (built-in)
- Note: If keychain is unavailable, passwords will be stored encrypted locally
- Linux:
You can install the CLI tool in two ways:
npm install -g https://github.com/paulgeorge35/db-cli# Clone the repository
git clone https://github.com/paulgeorge35/db-cli
cd db-cli
# Install dependencies
npm install
# Link the package globally
npm linkCreate named connections for different environments:
# Configure a production connection
db-cli config production
# Configure and set as default
db-cli config development --defaultThis interactive command will help you set up your database connection:
? Enter database host: localhost
? Enter database port: (5432)
? Enter database user: (root)
? Enter database name: (postgres)
? Enter connection description (optional): Development database
? Enter database password: [hidden]View all saved connections:
db-cli listExample output:
β Connections βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β Saved Connections: β
β β
β β’ production β
β Host: prod-db.example.com:5432 β
β User: app_user β
β Database: myapp_prod β
β Description: Production database β
β Password: β Stored β
β β
β β’ development (default) β
β Host: localhost:5432 β
β User: dev_user β
β Database: myapp_dev β
β Password: β Stored β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββView connection details and connection strings:
# View default connection
db-cli view
# View specific connection
db-cli view production
# Show password in connection string
db-cli view production --show-passwordSet a connection as the default:
db-cli default productionCreate a new database using a connection:
# Use default connection
db-cli add db
# Use specific connection
db-cli add db productionExample output:
? Enter the database name: myapp_staging
β Database created successfully!
Connection string:
postgresql://app_user:****@prod-db.example.com:5432/myapp_stagingRemove a saved connection:
db-cli delete stagingRemove all saved connections:
db-cli resetGet help on available commands:
db-cli --help
# Get help for specific commands
db-cli config --help
db-cli view --helpThe tool uses two secure storage mechanisms:
-
Connection configurations (host, port, username, database, description) are stored using the
confpackage in:- macOS:
~/Library/Preferences/db-cli-nodejs - Windows:
%APPDATA%/db-cli-nodejs/Config - Linux:
~/.config/db-cli-nodejs
- macOS:
-
Passwords are securely stored using a two-tier approach:
- Primary: System's native keychain (most secure)
- macOS: Keychain Access
- Windows: Credential Manager
- Linux: Secret Service API (GNOME Keyring/KWallet)
- Fallback: Encrypted local storage when keychain is unavailable
- Uses AES-256 encryption with machine-specific keys
- Automatically used on headless servers or systems without keyring services
- Primary: System's native keychain (most secure)
Each connection is stored independently, allowing you to manage multiple database environments securely. The tool will automatically use the most secure storage method available on your system.
| Command | Description | Example |
|---|---|---|
config <name> |
Configure a named connection | db-cli config production |
config <name> --default |
Configure and set as default | db-cli config dev --default |
list |
List all saved connections | db-cli list |
view [name] |
View connection details | db-cli view production |
view [name] -p |
View with password shown | db-cli view production -p |
default <name> |
Set default connection | db-cli default production |
add db [name] |
Create new database | db-cli add db staging |
delete <name> |
Delete connection | db-cli delete old-connection |
reset |
Remove all connections | db-cli reset |
# Set up different environments
db-cli config production
db-cli config staging
db-cli config development --default
# List all connections
db-cli list
# Create databases in different environments
db-cli add db production # Creates DB using production connection
db-cli add db # Creates DB using default (development) connection
# Switch default environment
db-cli default staging
# View connection details
db-cli view production --show-passwordCore dependencies:
boxen(^8.0.1): Create boxes in terminalchalk(^5.4.1): Terminal string stylingyargs(^18.0.0): Command-line argument parsinginquirer(^12.9.4): Interactive command promptspg(^8.11.3): PostgreSQL clientconf(^14.0.0): Configuration storagekeytar(^7.9.0): Secure password storage
If you encounter errors like [Error: Object does not exist at path "/org/freedesktop/secrets/collection/login"] on Ubuntu/Debian systems:
-
Install the required packages:
sudo apt-get update sudo apt-get install gnome-keyring libsecret-1-dev
-
For headless servers (VPS/Docker): The CLI will automatically use encrypted local storage as a fallback. You'll see a security notice when this happens.
-
Manual keyring setup (if needed):
# Start the keyring daemon eval $(gnome-keyring-daemon --start) export GNOME_KEYRING_CONTROL export SSH_AUTH_SOCK export GNOME_KEYRING_PID
- Permission errors: Ensure you have proper permissions to access the keychain/keyring
- Network connectivity: Verify your database server is accessible
- Node.js version: Ensure you're using Node.js 16.x or higher
If you're experiencing issues with password storage/retrieval, you can enable debug mode:
DB_CLI_DEBUG=1 db-cli view <connection-name>This will show additional information about keyring availability and fallback storage status.
This project is licensed under the MIT License - see the LICENSE file for details.
Paul George - contact@paulgeorge.dev
Project Link: https://github.com/paulgeorge35/db-cli