1 unstable release
| 0.1.0 | Jul 19, 2025 |
|---|
#1700 in Development tools
21 downloads per month
Used in 2 crates
14KB
361 lines
๐ ๏ธ dbctl
A flexible, user-friendly, and type-safe CLI + TUI tool written in Rust to create, run, and manage Dockerized databases (PostgreSQL, Redis, MariaDB, and more).
Built with love for learners and power users alike. ๐
๐ฏ Overview
dbctl simplifies database development and testing by providing:
-
Fast creation of Docker containers for popular databases
-
Easy management via both CLI and interactive TUI modes
-
Type-safe input collection and validation
-
Powerful insights with stats, logs, and connection details
-
Configuration persistence with JSON-based profiles
Supported Databases
- ๐ PostgreSQL - Full-featured, robust relational database
- ๐ Redis - In-memory data structure store
- ๐ฌ MariaDB - Community-developed fork of MySQL
- โ Extensible architecture for adding more database types
๐ Quick Start
# Install from crates.io
cargo install dbctl
# Create a PostgreSQL database
dbctl create postgres --name mypg --user admin --password secret --port 5432
# Launch the interactive TUI wizard
dbctl wizard
๐ Development Roadmap
| Week | Focus | Goals |
|---|---|---|
| 1 | โ Setup + CLI/TUI Basics | Rust, project layout, clap, ratatui |
| 2 | ๐ข๏ธ PostgreSQL support | Database trait, default configs |
| 3 | ๐ณ Docker integration | Launch & manage containers |
| 4 | โ๏ธ CLI Command: Create | Launch Postgres via CLI |
| 5 | ๐จ TUI Wizard | Select DB & enter info visually |
| 6 | ๐งฉ Add Redis, MariaDB | Implement additional backends |
| 7 | ๐ Stats & Logging | Show container stats, logs, inspect |
| 8 | ๐งช Error Handling & Polish | thiserror, tracing, UX |
โ Feature Checklist
๐๏ธ Core Project Setup
- Project Initialization with
cargo new - Modular Folder Structure
- Logging with
tracing - Error handling with
thiserror
โ๏ธ CLI Interface (clap)
- Create database (PostgreSQL)
- Create database (Redis)
- Create database (MariaDB)
- Inspect running containers
- Show container logs
- Delete database containers
๐จ TUI Wizard (ratatui)
- Select database type
- Input config values with validation
- Preview config before launching
- Display creation results and info
- Add theme/colors and improved UX
๐ณ Docker API (bollard)
-
Start Postgres container
-
Start Redis container
-
Start MariaDB container
-
View stats/logs of container
-
Return container ID + connection URL
-
Stop and remove containers
๐ JSON Config Support
-
Load config from file
-
Save config to file
-
Update config (edit mode)
๐ Project Architecture
dbctl/
โโโ Cargo.toml
โโโ README.md
โโโ src/
โ โโโ main.rs # Entry point
โ โโโ cli/ # CLI command handling
โ โ โโโ mod.rs
โ โโโ tui/ # Terminal UI components
โ โ โโโ mod.rs
โ โโโ db/ # Database implementations
โ โ โโโ mod.rs
โ โ โโโ postgres.rs
โ โ โโโ redis.rs
โ โ โโโ mariadb.rs
โ โโโ docker/ # Docker interaction
โ โ โโโ engine.rs
โ โโโ config/ # Configuration handling
โ โ โโโ models.rs
โ โโโ output.rs # Output formatting
โ โโโ utils.rs # Utility functions
โ โโโ error.rs # Error types
๐ป Usage Examples
Command-Line Interface
# Create a PostgreSQL database
$ dbctl create postgres \
--name mypg \
--user admin \
--password secret \
--port 5432
โ
Database 'mypg' started in Docker
๐ URL: postgres://admin:secret@localhost:5432/mypg
๐ Container ID: 17afc8c9d16
# List running database containers
$ dbctl list
# View container logs
$ dbctl logs mypg
# Stop and remove a container
$ dbctl remove mypg
Terminal User Interface
The TUI provides an interactive wizard for configuring and launching databases:
+------------------------------------------+
| Select a Database to Launch |
| > PostgreSQL |
| Redis |
| MariaDB |
+------------------------------------------+
+------------------------------------------+
| ๐งพ PostgreSQL Setup |
| Name : mypg |
| Username : admin |
| Password : ****** |
| Host : localhost |
| Port : 5432 |
| SSL? : [ No ] |
+------------------------------------------+
| [ Create Database ] |
+------------------------------------------+
โ
Success! Container Started
๐ URL: postgres://admin:secret@localhost:5432/mypg
๐ Container ID: 17afc8c9d16
๐ง Database Configuration
Configurations can be saved as JSON profiles for reuse:
{
"type": "postgres",
"name": "mypg",
"user": "admin",
"password": "secret",
"host": "localhost",
"port": 5432,
"db_name": "mypg",
"ssl": false
}
Load saved configurations:
$ dbctl create --from-file postgres-dev.json
๐ ๏ธ Installation
Prerequisites
-
Rust toolchain (stable)
-
Docker installed and running
From Source
# Clone the repository
git clone https://github.com/yourusername/dbctl.git
cd dbctl
# Build and install
cargo install --path .
๐ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
Dependencies
~12โ27MB
~321K SLoC