A Python CLI application for managing a person database with support for SQLite and MySQL backends. Built with Peewee ORM, Typer CLI framework, and Rich for beautiful terminal output.
- Python 3.7+
- pip
Install the required packages:
pip install -r requirements.txtFor MySQL support, also install:
pip install PyMySQLpython main.py create "John Doe" 30python main.py listThe application uses SQLite by default with a file named persons.db. You can configure different database backends in the code:
configure_database('sqlite', database='my_app.db')configure_database('mysql',
database='my_db',
user='username',
password='password',
host='localhost',
port=3306)Configure the database connection.
Parameters:
db_type: Either 'sqlite' or 'mysql'**kwargs: Database-specific configuration options
Decorator that automatically manages database connections for functions.
@with_database
def my_database_function():
# Database operations here
person = Person.create(name="Example", age=25)
return personCreates database tables if they don't already exist.
Database/
├── database.py # Database models and connection management
├── main.py # CLI application entry point
├── README.md # This file
├── tests/
│ └── test_database.py # Test suite
└── logs/ # Application logs (created automatically)
├── app.log
└── database.log
The application uses Loguru for comprehensive logging:
- Application logs:
logs/app.log - Database logs:
logs/database.log
Logs are automatically rotated (1 MB) and retained for 10 days.
Run the test suite:
pytest tests/Run with coverage:
pytest tests/ --cov=database --cov-report=htmlMIT License