Skip to main content

PostgreSQL for Gevent kept Simple.

Project description

Provides:

  • db(sql, *values).row|s

  • id = db_insert(**kw)

  • db_update(**kw)

  • with db_transaction

  • raise db_rollback

  • patch, log, pool, reconnect, retry.

Usage:

sudo apt-get install --yes gcc libevent-dev libpq-dev python-dev
sudo pip install pg4geks

from pg4geks import db, db_config, 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.column == row['column'] or row is None

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 on iteration.

try:

    with db_transaction():
        db('INSERT INTO table1 (quantity) VALUES (%s)', -100)
        db('INSERT INTO table2 (quantity) VALUES (%s)', +1/0)

        if error:
            raise db_rollback
except db_rollback:
    pass # Or not.

id = db_insert('table',
    related_id=related_id,
    parent_id=parent_id,
    _return='id',
)

db_update('table',
    related_id=None,
    where=dict(id=id),
)

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

pg4geks-0.1.1.tar.gz (4.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page