Skip to main content

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.

Files for Conntext, version 0.1.5
Filename, size File type Python version Upload date Hashes
Filename, size Conntext-0.1.5.tar.gz (2.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page