A quality-of-life wrapper for the psycopg2 connection object.
Project description
lonny_common_pg
A quality-of-life wrapper for the psycopg2 connection object.
Installation
pip install lonny_common_pg
Usage
To import the connection object, simply do:
from lonny_common_pg import Connection
- The connection object constructor takes
host
,port
,dbname
,user
andpassword
kwargs. - The connection isn't initialized until a query is made or
init
is explicitly called. - The connection can be closed by using
close
- however it can be subsequently re-opened at anytime. When used in awith
contextmanager context - the connection is closed when leaving the block. - The 3 methods for querying the database are:
execute
,fetch_one
andfetch_all
. All of these can either take a SQL string, or a callable (see thelonny_sql
module for usage). - This connection wrapper uses
autocommit
mode and theDictCursor
for returning results.
Nested Transactions
Nested transactions are possible using this library. The outermost transaction uses a standard TRANSACTION
construct. Inner transactions use a SAVEPOINT
instead.
conn = Connection(**kwargs)
with conn.transaction():
try:
do_something_else()
with conn.transaction():
do_something()
except:
pass
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
lonny_common_pg-0.1.0.tar.gz
(3.5 kB
view details)
Built Distribution
File details
Details for the file lonny_common_pg-0.1.0.tar.gz
.
File metadata
- Download URL: lonny_common_pg-0.1.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.8.3 Linux/4.15.0-112-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b897a0744f440f016a46ccad5448ed9a24ebd2b1a55b3a6c7ab8d23c664da3e |
|
MD5 | f0eb95e813a7e90dc4b3d3616422f22c |
|
BLAKE2b-256 | b15a0d1e22752d864a21ccc7670497c19ecaefc485a0c046f5067737c7f46d9d |
File details
Details for the file lonny_common_pg-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: lonny_common_pg-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.8.3 Linux/4.15.0-112-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a79b40fdb64835db5d9a279bdca0b8c4e8d46d18084c7ccccfe2db580ad4d019 |
|
MD5 | c326ee487a18abfb37e31b4188483f24 |
|
BLAKE2b-256 | 48ac42366446ddb66d86f3126796f84a82806e297a4a1ed92bcb6e2dfb58c803 |