Skip to main content

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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Spilli-DBAL 1.1.1
File Size Uploaded
spilli_dbal-1.1.1.tar.gz 40.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Spilli-DBAL 1.1.1
File Interpreter ABI Platform
spilli_dbal-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 69.9 kB

Release files / spilli_dbal-1.1.1.tar.gz

Download URL spilli_dbal-1.1.1.tar.gz
Size 40.1 kB
Tags Source
SHA-256 checksum
How to use checksums
16fd4abb7f92efb10890cd7261993a685d520e790586ea5291e9a89dfbd22c74
BLAKE2b-256 checksum
How to use checksums
88dcbc61f2071d98391bc1f4a4b9793df64c677fc154c79939bfce7f8cbccbaa
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.1-py3-none-any.whl

Download URL spilli_dbal-1.1.1-py3-none-any.whl
Size 29.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df01df24236bd653911d09fbdbe44bac6414df5d5cdd938aa28396a42e95efa4
BLAKE2b-256 checksum
How to use checksums
e6cea450a3efc76120cb2f9dfc1a178824eaa32bee72f2dc940718fde1f34928
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page