classic-sql-storage-0.0.1
توضیحات
Provides primitives for contextual transactions processing with SQLALchemy and base for repository class
| ویژگی | مقدار |
|---|---|
| سیستم عامل | OS Independent |
| نام فایل | classic-sql-storage-0.0.1 |
| نام | classic-sql-storage |
| نسخه کتابخانه | 0.0.1 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Sergei Variasov |
| ایمیل نویسنده | variasov@gmail.com |
| آدرس صفحه اصلی | https://github.com/variasov/classic_sql_storage |
| آدرس اینترنتی | https://pypi.org/project/classic-sql-storage/ |
| مجوز | - |
# Classic SQL Storage
This package provides contextual transactions processing for SQLAlchemy and
base for pattern "Repository".
Part of project "Classic".
Usage:
```python
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()
```
نیازمندی
| مقدار | نام |
|---|---|
| ~=1.4.23 | sqlalchemy |
| ~=0.0.1 | classic-components |
| ~=6.2.5 | pytest |
| ~=2.12.1 | pytest-cov |
| ~=3.4.2 | twine |
| ~=0.7.0 | build |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.7 | Python |
نحوه نصب
نصب پکیج whl classic-sql-storage-0.0.1:
pip install classic-sql-storage-0.0.1.whl
نصب پکیج tar.gz classic-sql-storage-0.0.1:
pip install classic-sql-storage-0.0.1.tar.gz