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.2.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

classic_sql_storage-0.0.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file classic_sql_storage-0.0.2.tar.gz.

File metadata

  • Download URL: classic_sql_storage-0.0.2.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for classic_sql_storage-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f7eee7a252537bd026bed4a7ea3792370eaae99139dfedebdd6e47ea3690f78e
MD5 791ac68c4c5aa4f2fa8f990ea8a0391f
BLAKE2b-256 e296fd3f691cae1b1e021fbf79428e3a5172173ac64a0351e35087c3142ebb47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for classic_sql_storage-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8d4de788121a685753f112a5434d98da3b1f6646161badd02d9d6f587c64d0a6
MD5 9dd342c5ae146ba8e514cc06266bfb0e
BLAKE2b-256 c798e10e9b0027afd52b30b01d04a56eaf1c67aed95b1ad446a1e36f38b1f56b

See more details on using hashes here.

Supported by

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