Tiny helper to map simple Python class-like metadata to SQLite tables. This repo contains a minimal, easy-to-read implementation suitable for small projects and examples.
- (Optional) set the database location:
export CLASS_TO_SQL_DB=$(pwd)/db/peppermint.db- Run the example or import in Python (ensure
src/is onPYTHONPATHor install editable):
python examples/basic.pyor in Python:
from class_to_sql.base_dataclass import Base
base = Base()
meta = {
'id': int,
'name': str,
'super': {'primary_key': ['id'], 'defaults': {}}
}
Base.create_table('users', meta)
base.callback_create('users', {'id': 1, 'name': 'Alice'}, meta)Create a virtual environment and install test deps:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install black ruffRun linter/formatter checks and tests:
ruff check .
black --check .
pytest -q- By default the package writes the SQLite DB to
db/peppermint.dbin the repository root whenCLASS_TO_SQL_DBis not set. - The implementation uses parameterized SQL for DML to reduce injection risks. DDL still interpolates table/column names and should be used with trusted metadata.
- Tests use a temporary DB file and set
CLASS_TO_SQL_DBto keep runs hermetic.