skip to navigation
skip to content

Not Logged In

Conntext 0.1.4

Context managers for secure and atomic database connectivity

Latest Version: 0.1.5

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+).

 
File Type Py Version Uploaded on Size
Conntext-0.1.4.tar.gz (md5) Source 2014-04-12 2KB
  • Downloads (All Versions):
  • 35 downloads in the last day
  • 105 downloads in the last week
  • 200 downloads in the last month
  • Author: James Nah
  • Home Page: https://github.com/microamp/conntext
  • License:
    Copyright (C) 2014  James Nah <sangho.nah@gmail.com>
    
    This library is free software: you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public License
    as published by the Free Software Foundation, either version 3 of
    the License, or (at your option) any later version.
    
    This library is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Lesser General Public License for more details.
    
    You should have received a copy of the GNU Lesser General Public
    License along with this program. If not, see <http://www.gnu.org/licenses/>.
  • Package Index Owner: microamp
  • DOAP record: Conntext-0.1.4.xml