Spilli-DBAL
Web-framework independent CRUD tools for working with database via SQLAlchemy.
Features
- DBAL - database access layer.
- CRUD methods for create, read, update and delete object from database.
- Bulk methods for create, read, update and delete object from database.
- Method of paginating data.
- StatementMaker class for create query 'per-one-model'.
- Marshmallow (https://github.com/marshmallow-code/marshmallow) schemas for serialization input data for pagination.
- Marshmallow schemas for deserialization SQLAlchemy result object to
dict. - Datetime with UTC timezone validation in
BaseSchema.
Installation
Recommended using the latest version of Python. Spilli-DBAL supports Python 3.12 and newer.
Install and update using pip:
$ pip install -U spilli_dbal
Examples
Full example
from spilli_dbal.base_model import ModelMixin
from spilli_dbal.dbal import SqlaDBAL
from spilli_dbal.dbal.exceptions import DBALObjectNotFoundException
from sqlalchemy import create_engine
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
from sqlalchemy.orm import Session
engine = create_engine('sqlite://', echo=True, future=True)
session = Session(engine)
Base = declarative_base()
class Items(ModelMixin, Base):
__tablename__ = 'items'
data: Mapped[str] = mapped_column(comment='Data of item.')
Base.metadata.create_all(engine)
class ItemsDBAL(SqlaDBAL[Items]):
"""Items DBAL."""
if __name__ == '__main__':
new_item = ItemsDBAL(session).create(data='data')
print('=>', 'New item:', new_item)
item = ItemsDBAL(session).read(id=new_item.id)
print('=>', 'Item:', item)
updated_item = ItemsDBAL(session).update(id=new_item.id, data='updated_data')
print('=>', 'Updated item:', updated_item)
ItemsDBAL(session).delete(id=new_item.id)
try:
ItemsDBAL(session).read(id=new_item.id)
except DBALObjectNotFoundException:
print('=>', 'Deleted item.')
Metadata
Release files for Spilli-DBAL 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| spilli_dbal-1.0.0.tar.gz | 14.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spilli_dbal-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.2 kB
Release files / spilli_dbal-1.0.0.tar.gz
| Download URL | spilli_dbal-1.0.0.tar.gz |
|---|---|
| Size | 14.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2442f7554f97f5710659b1ffda499ced950f88bb6bd39a4bb002dfef1efca9e4
|
|
BLAKE2b-256 checksum How to use checksums |
8be88dd1d85182d41b7b7f18e5f5f743324e757291b11a37e6e68241759e7150
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / spilli_dbal-1.0.0-py3-none-any.whl
| Download URL | spilli_dbal-1.0.0-py3-none-any.whl |
|---|---|
| Size | 12.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c54ed4378e66be3c67775f0e5b8a0e9e292b420a8769c50e7bc7bc0934b6a7d9
|
|
BLAKE2b-256 checksum How to use checksums |
f439e309d47c12ef9399dd1a4cc764caa7f1ac59f212900055e7fdf970cb87ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|