| Crates.io | dbhub |
| lib.rs | dbhub |
| version | 1.4.0 |
| created_at | 2025-06-11 09:13:53.762+00 |
| updated_at | 2025-08-15 09:31:48.456985+00 |
| description | A CLI tool to manage your multi-environment database configurations, and easily connect to them. Now it supports MySQL, Redis, Redis Sentinel, MongoDB, Memcached database and you can easily add a custom db-type by write a lua scripts. |
| homepage | |
| repository | https://github.com/yeqown/dbhub |
| max_upload_size | |
| id | 1708363 |
| size | 607,077 |
A command-line tool for managing multiple database connections across different environments. Supports MySQL, MongoDB, DocumentDB, Doris, and Redis databases.
cargo binstall dbhub
# or
cargo install dbhub
Usage: dbhub [OPTIONS] [COMMAND]
Commands:
connect Connect to a database using environment and database name
context Manage database connection contexts
help Print this message or the help of the given subcommand(s)
Options:
-c, --config <CONFIG> Config file path
-h, --help Print help
-V, --version Print version
# dbhub connect $DB_CONTEXT_ALIAS
# or using connect command short alias: c
dbhub connect my-local-mysql
# same as above
dbhub c my-local-redis
# passthrough args to lua script if it supports. such as scripts/mongo.lua
# so that the mongo.lua script can receive `--db=test` in `runtime_args` to specify
# the target database at run time.
dbhub c my-local-mongo -- --db=test
# show all contexts
dbhub context
# or filter by env: only show `local` databases
dbhub context --filter-env=local
# or filter by database type: only show `mysql` databases
dbhub context --filter-db-type=mysql
The configuration file is stored at ~/.dbhub/config.yml with the following format:
# This is a sample configuration file for the dbhub CLI.
# You can use this file to configure the CLI to connect to your databases.
# The CLI will look for this file in the following locations:
# - $HOME/.dbhub/config.yml
# or you can specify the path to the file using the --config flag.
# For more information, see the README.md file.
# `databases` section is a list of databases that you want to connect to.
# Each database has the following fields:
# - `alias`: The alias of the database.
# You can use this alias to connect to the database.
#
# - `db_type`: indicates the type of the database helps dbhub to choose database CLI.
# Now, dbhub supports `mysql`, `mongo`, `redis`.
#
# - `dsn`: Connection string of the database which obeys the templates.dsn.
# For example, the dsn for mysql is mysql://{user}:{password}@tcp({host}:{port})/{database}?{query}
#
# - `env`: The environment of the database.
#
# - `description`: A string to describe the database detailed.
#
# - `annotations`: A Key-Value map of annotations for the database.
databases:
- alias: my-local-mysql
db_type: mysql
dsn: "mysql://root:root@tcp(localhost:3306)/db?parseTime=True"
env: local
description: "The local mysql database for quickly testing dbhub CLI."
annotations:
mysql: "1"
version: "8.0.32"
- alias: my-local-mongo
db_type: mongo
dsn: "mongodb://user:password@localhost:27017/db"
env: local
description: "The local mongo database for quickly testing dbhub CLI."
annotations:
mongo: "1"
version: "6.0.1"
- alias: my-local-redis
db_type: redis
dsn: "redis://user:password@localhost:6379/0"
env: local
description: "The local redis database for quickly testing dbhub CLI."
annotations:
redis: "1"
version: "7.2.1"
- alias: my-local-redis-sentinel
db_type: redis-sentinel
dsn: "redis://user:password@localhost:6379/0"
env: local
description: "The local redis sentinel database for quickly testing dbhub CLI."
annotations:
redis-sentinel/mastername: "mymaster"
- alias: my-local-memcached
db_type: memcached
dsn: "memcached://localhost:11211,localhost:11212"
env: local
description: "The local memcached database for quickly testing dbhub CLI."
annotations:
memcached/hash-distribution: "murmur3"
# `templates` section is a list of template related to a specified database type including `dsn` and `cli`.
# Each template has the following fields:
# - `dsn`: Connection string of the database which obeys the templates.dsn.
# For example, the dsn for mysql is mysql://{user}:{password}@tcp({host}:{port})/{database}?{query}
#
# - `cli`: The command to connect to the database.
# For example, the cli for mysql is mysql -h{host} -P{port} -u{user} -p{password} {database}
templates:
mysql:
dsn: mysql://{user}:{password}@tcp({host}:{port})/{database}?{query}
mongo:
dsn: mongodb://{user}:{password}@{host}:{port}/{database}?{query}
redis:
dsn: redis://{user}:{password}@{host}:{port}/{database}
memcached:
dsn: memcached://{servers}
dbhub supports shell completion for zsh, bash, fish, and PowerShell.
Use the provided installation script:
# Install zsh completion (default)
./scripts/install-completion.sh
# Install for other shells
./scripts/install-completion.sh bash
./scripts/install-completion.sh fish
./scripts/install-completion.sh powershell
# Generate completion script
dbhub completion zsh > ~/.zsh/completions/_dbhub
# Add to your .zshrc if not already present
echo 'fpath=(~/.zsh/completions $fpath)' >> ~/.zshrc
echo 'autoload -U compinit && compinit' >> ~/.zshrc
# Reload your shell
source ~/.zshrc
# Generate completion script
dbhub completion bash > ~/.bash_completion.d/dbhub
# Add to your .bashrc if not already present
echo 'for f in ~/.bash_completion.d/*; do source $f; done' >> ~/.bashrc
# Reload your shell
source ~/.bashrc
# Generate completion script
dbhub completion fish > ~/.config/fish/completions/dbhub.fish
# Generate completion script and add to your profile
dbhub completion powershell >> $PROFILE
MIT