https://github.com/bixoto/bixomix
Collection of SQLAlchemy mixins
https://github.com/bixoto/bixomix
python3 sqlalchemy
Last synced: about 2 months ago
JSON representation
Collection of SQLAlchemy mixins
- Host: GitHub
- URL: https://github.com/bixoto/bixomix
- Owner: Bixoto
- License: mit
- Created: 2023-03-30T15:56:32.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-10T17:29:13.000Z (11 months ago)
- Last Synced: 2025-04-14T23:14:46.200Z (about 2 months ago)
- Topics: python3, sqlalchemy
- Language: Python
- Homepage:
- Size: 49.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Bixomix
**bixomix** is a collection of SQLAlchemy mixins.
## Support
* Python 3.9+
* SQLAlchemy 2.0+## Install
pip install bixomix
## Usage
Add mixins after the `Base` class in each model’s parent classes. The order of the mixins doesn’t matter.
```python
from sqlalchemy.orm import DeclarativeBasefrom bixomix import CreatedAtMixin, EnabledMixin
class Base(DeclarativeBase):
passclass MyModel(Base, CreatedAtMixin, EnabledMixin):
# Add your own fields here
...
```## Mixins
* `CreatedAtMixin`: add a `created_at` datetime field that’s automatically filled with the record’s creation date
* `UpdatedAtMixin`: add an `updated_at` datetime 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](https://stackoverflow.com/a/71072370/735926).
* `CreatedUpdatedAtMixin`: combined version of the previous two mixins
* `EnabledMixin`: add an `enabled` boolean field (default is `true`)
* `EnabledNoMixin`: same as `EnabledMixin`, but the default value is `false`
* `UpdateFromDictMixin`: add an `update_from_dict` method to update a model in-place given a dictionary of attributes