Skip to main content

A sprockets mixin that automatically connects to PostgreSQL

Project description

Handler mixins that automatically connect a PostgreSQL client session upon initialization.

Version Downloads Status Coverage License

Installation

sprockets.mixins.postgresql is available on the Python Package Index and can be installed via pip or easy_install:

pip install sprockets.mixins.postgresql

Documentation

https://sprocketsmixinspostgresql.readthedocs.org

Requirements

Example

The following example demonstrates using the HandlerMixin with a synchronous Tornado RequestHandler <tornado.web.RequestHandler> for a database named postgres:

import os

from sprockets.mixins import postgresql
from tornado import web

os.environ['POSTGRES_HOST'] = 'localhost'
os.environ['POSTGRES_USER'] = 'postgres'
os.environ['POSTGRES_PORT'] = 5432
os.environ['POSTGRES_DBNAME'] = 'postgres'

class PostgresRequestHandler(postgresql.HandlerMixin,
                             web.RequestHandler):

    DBNAME = 'postgres'

    def get(self, *args, **kwargs):
        result = self.foo_session.query('SELECT * FROM bar')
        self.finish({'data': result.items()})

The second example demonstrates using the AsyncHandlerMixin with an asynchronous Tornado RequestHandler for a database named foo:

import os

from sprockets.mixins import postgresql
from tornado import web

os.environ['FOO_HOST'] = 'localhost'
os.environ['FOO_USER'] = 'postgres'
os.environ['FOO_PORT'] = 5432
os.environ['FOO_DBNAME'] = 'foo'
os.environ['FOO_PASSWORD'] = 'bar'

class FooRequestHandler(postgresql.AsyncHandlerMixin,
                        web.RequestHandler):

    DBNAME = 'foo'

    @web.asynchronous
    def get(self, *args, **kwargs):
        result = yield self.foo_session.query('SELECT * FROM baz')
        self.finish({'data': result.items()})
        result.free()

Version History

Available at https://sprocketsmixinspostgresql.readthedocs.org/en/latest/history.html

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

sprockets.mixins.postgresql-1.0.1.tar.gz (8.6 kB view details)

Uploaded Source

File details

Details for the file sprockets.mixins.postgresql-1.0.1.tar.gz.

File metadata

File hashes

Hashes for sprockets.mixins.postgresql-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6ab2db8947b2b273a7ada242980f29148fe268553f37d875ceac07f43e291052
MD5 e133b5c9ff0166b0cbd5bdf1b7e3f4fe
BLAKE2b-256 1a6c5fe7d4c9b89cb6b26b0256b6cac360a10365c9129fbc29cf7d249297df6c

See more details on using hashes here.

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