Easily wrap connections and cursors by using decorators.
Project description
wrap-connection
Easily wrap connections and cursors by using decorators.
Usage example:
A simple usage is this:
def make_connection():
import sqlite3
return sqlite3.connect("test.db")
@transact(make_connection, "cur", "con")
def some_operation(person):
insert_sql = "INSERT INTO persons (id, name) VALUES (?, ?)"
cur.execute(insert_sql, (person.id, person.name))
con.commit()
@transact(make_connection)
def some_other_operation():
select_sql = "SELECT id, name FROM persons"
result = []
cursor.execute(select_sql)
for r in cursor.fetchall():
result.append(Person(r[0], r[1]))
return result
Those will delimite a transaction in the some_operation and some_other_operation functions. The make_connection function is used to get the connection for each transaction.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file wrap-connection-2.0.0.0.tar.gz.
File metadata
- Download URL: wrap-connection-2.0.0.0.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50b4ad939dc7ff1caecce0c735ca93d15784e86326762fc0242066abe16d54b5
|
|
| MD5 |
19d517a585409cf00230e4f5eefe9f9e
|
|
| BLAKE2b-256 |
65dcfe4358d481e154086ec4fadaaffae6fbe3cb175697d901ac23c5c23f9c13
|