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