Provides:
db(sql, *values).row/rows/affected
id = db_insert(table_name, _return='id', name=value,..)
affected = db_update(table_name, where=dict(name=value, item_in=tuple_of_values), name=value,..)
result = db_transaction(code)
raise db_rollback
db("""ALTER TYPE "my_type" ADD VALUE 'my_value'""", autocommit=True) # Avoid "cannot run inside a transaction block".
db('SELECT * FROM "table" WHERE "name" LIKE %s', escape_like(fragment))
connection pool blocks only for the first connection - for quick deploy
auto reconnect and retry
optional log of each query
Usage:
sudo apt-get install --yes gcc libevent-dev libpq-dev python-dev
sudo pip install pg4geks
from pg4geks import db, db_config, db_insert, db_update, db_transaction
db_config(name='test', user='user', password='password')
# Defaults: host='127.0.0.1', port=5432, pool_size=10, patch_psycopg2_with_gevent=True, log=None
row = db('SELECT "column" FROM "table" WHERE "id" = %s', id).row
assert row is None or row.column == row['column']
return db('SELECT * FROM "table" WHERE "related_id" IN %s AND "parent_id" = %s', tuple(related_ids), parent_id).rows
# Please note that "tuple()" should be used with "IN %s", to keep "list []" for PostgreSQL Array operations.
# http://pythonhosted.org/psycopg2/usage.html#adaptation-of-python-values-to-sql-types
return [
processed(row)
for row in db('SELECT * FROM "table" LIMIT 10')
] # Please note that no ").rows" is required for iteration.
try:
def code():
db('INSERT INTO "table1" ("quantity") VALUES (%s)', -100)
db('INSERT INTO "table2" ("quantity") VALUES (%s)', +1/0)
if error:
raise db_rollback
return result
result = db_transaction(code)
except db_rollback:
pass # Or not.
id = db_insert('table',
related_id=related_id,
parent_id=parent_id,
_return='id',
)
assert db_update('table',
related_id=None,
where=dict(id=id), # Or: id=tuple(ids_to_update)
) == 1
# See tests for more usage examples.
Metadata
Release files for pg4geks 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pg4geks-0.2.3.tar.gz | 5.3 kB | Without provenance | Details for pg4geks-0.2.3.tar.gz |
Release files / pg4geks-0.2.3.tar.gz
| Download URL | pg4geks-0.2.3.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2a01e47aa43f528d2edae6e2e11a2db2ce7d89604d8adb66a22787674e2961cc
|
|
BLAKE2b-256 checksum How to use checksums |
2ea35cb43d79eeeb0714c7692cb1ca54fa21a60a8e69b2176641d476720e1e64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for pg4geks 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.