Skip to main content

Provides primitives for contextual transactions processing with SQLALchemy and base for repository class

Project description

Classic SQL Storage

This package provides contextual transactions processing for SQLAlchemy and base for pattern "Repository".

Part of project "Classic".

Usage:

from classic.sql_storage import TransactionContext
from sqlalchemy import create_engine, text


engine = create_engine('sqlite:///')

transaction = TransactionContext(bind=engine)


# As context manager:
with transaction:
    transaction.current_session.execute(
        text('SELECT 1')
    )


# As decorator:
@transaction
def some_work():
    transaction.current_session.execute(
        text('SELECT 1')
    )


# Propagation:
@transaction
def complex_function():
    """Doing complex work with db.
    Session will be commited only after finish of complex_function call.
    TransactionContext will count all calls, and will commit or rollback session
    only in last call.
    """
    some_work()
    some_work()
    some_work()
    
    with transaction:
        transaction.current_session.execute(
            text('SELECT 1')
        )


# Automatic rollback
@transaction
def function_with_error():
    """Changes, made by some_work, will be cancelled after raising error"""
    some_work()
    raise ValueError()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

classic-sql-storage-0.0.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

classic_sql_storage-0.0.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file classic-sql-storage-0.0.1.tar.gz.

File metadata

  • Download URL: classic-sql-storage-0.0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.3

File hashes

Hashes for classic-sql-storage-0.0.1.tar.gz
Algorithm Hash digest
SHA256 d4377438c7e9c554d95d5a6838a1e291f3dcb7bd677c7915b87fc8966dff2335
MD5 a27ad8a715b17a4929e705687bb1170c
BLAKE2b-256 8cf026b5968a92277f727c89fc85da799848d994160e3cfefa6cac8fbd874412

See more details on using hashes here.

File details

Details for the file classic_sql_storage-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: classic_sql_storage-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.3

File hashes

Hashes for classic_sql_storage-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 980982032b6ae51e29fa56fb6eede8cfffe1d7c50db283a346e36ebd416adfdb
MD5 3795ee1d3623ea93239e4081f228303d
BLAKE2b-256 1bd16fdb7ed0b7c56d899dea9e1a69f4a3a4e08e574367ae605bbeda76226d48

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page