bixomix is a collection of SQLAlchemy mixins.
- Python 3.9+
- SQLAlchemy 2.0+
pip install bixomix
Add mixins after the Base class in each model’s parent classes. The order of the mixins doesn’t matter.
from sqlalchemy.orm import DeclarativeBase
from bixomix import CreatedAtMixin, EnabledMixin
class Base(DeclarativeBase):
pass
class MyModel(Base, CreatedAtMixin, EnabledMixin):
# Add your own fields here
...CreatedAtMixin: add acreated_atdatetime field that’s automatically filled with the record’s creation dateUpdatedAtMixin: add anupdated_atdatetime field that’s automatically filled with the record’s last update date. Note that on Postgres this is done in Python; for a database-level update you have to create a trigger.CreatedUpdatedAtMixin: combined version of the previous two mixinsEnabledMixin: add anenabledboolean field (default istrue)EnabledNoMixin: same asEnabledMixin, but the default value isfalseUpdateFromDictMixin: add anupdate_from_dictmethod to update a model in-place given a dictionary of attributes