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 schemas for serialization input data for StatementMaker.
- Marshmallow schemas for deserialization StatementMaker 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.models.base 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.')
Project automation
All commands are defined in the Makefile.
Builds the package, installs it from the sdist, and installs pre-commit hooks into git
make install
Run for build, install and test project.
make all
Metadata
Release files for Spilli-DBAL 1.1.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.1.0.tar.gz | 39.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spilli_dbal-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 69.8 kB
Release files / spilli_dbal-1.1.0.tar.gz
| Download URL | spilli_dbal-1.1.0.tar.gz |
|---|---|
| Size | 39.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5531d6f0c73ab6dedaf1fe8d26820bcdf1e1805d860be53274631b745f07b10a
|
|
BLAKE2b-256 checksum How to use checksums |
13aca110250c769478e5515073b90959c9aba163ec9ed39e4a0a99fe8acbd4d3
|
| 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.1.0-py3-none-any.whl
| Download URL | spilli_dbal-1.1.0-py3-none-any.whl |
|---|---|
| Size | 29.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
94b0402101d937e24b13d4f969c024fefb86b247d0c82f1c66d43bd1f89d85d9
|
|
BLAKE2b-256 checksum How to use checksums |
7353d882876e28339d53bc66036a6da483001d44b9c289ee4e4c57b69336493d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|