Context managers for secure and atomic database connectivity
Project description
Context managers for secure and atomic database connectivity
Rationale
Each context being a single atomic process (“either all occur, or nothing occurs”)
No manual commit (success), rollback (fail) or close (either)
No ORM
Usage
Without Conntext,
conn = sqlite3.connect(":memory:")
try:
cursor = conn.cursor()
try:
cursor.execute("CREATE TABLE person (name)")
cursor.execute("INSERT INTO person (name) VALUES (?)",
["microamp"])
except Exception:
raise
finally:
cursor.close()
except Exception:
conn.rollback()
raise
else:
conn.commit()
finally:
conn.close()
With Conntext,
from conntext import conntext
with conntext.conn(sqlite3.connect(":memory:")) as conn:
with conntext.cursor(conn.cursor()) as cursor:
cursor.execute("CREATE TABLE person (name)")
cursor.execute("INSERT INTO person (name) VALUES (?)",
["microamp"])
License
All the code is licensed under the GNU Lesser General Public License (v3+).
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
Conntext-0.1.5.tar.gz
(2.4 kB
view details)
File details
Details for the file Conntext-0.1.5.tar.gz.
File metadata
- Download URL: Conntext-0.1.5.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0c7b659bf1c10e4295dce766e2f1a45dfbcb593c87730ed5a861fd01932c653
|
|
| MD5 |
58434ba67f3588692cd3677d2816fe2e
|
|
| BLAKE2b-256 |
5e33e74939f6e453e032cb9b8c3089b3124fd91de771efaa8379bebb336e6b68
|