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


Release history Release notifications

History Node

0.1.5

This version
History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
Conntext-0.1.4.tar.gz (2.5 kB) Copy SHA256 hash SHA256 Source None Apr 12, 2014

Supported by

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