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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7eee7a252537bd026bed4a7ea3792370eaae99139dfedebdd6e47ea3690f78e
|
|
| MD5 |
791ac68c4c5aa4f2fa8f990ea8a0391f
|
|
| BLAKE2b-256 |
e296fd3f691cae1b1e021fbf79428e3a5172173ac64a0351e35087c3142ebb47
|
File details
Details for the file classic_sql_storage-0.0.2-py3-none-any.whl.
File metadata
- Download URL: classic_sql_storage-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d4de788121a685753f112a5434d98da3b1f6646161badd02d9d6f587c64d0a6
|
|
| MD5 |
9dd342c5ae146ba8e514cc06266bfb0e
|
|
| BLAKE2b-256 |
c798e10e9b0027afd52b30b01d04a56eaf1c67aed95b1ad446a1e36f38b1f56b
|