Skip to main content

Route postgres connections and hook into cursor execution

Project description

django-pgconnection provides primitives for overriding Postgres connection and cursor objects, making it possible to do the following:

  1. Hook into SQL generation. For example, it is not possible to log every time a SQL statement is executed in Django or annotate SQL with comments so that additional metadata is logged when executing queries. The pgconnection.pre_execute_hook context manager allows one to hook into SQL before it is executed.

  2. Route database traffic to a different database. Although Django provides the ability to construct custom database routers, routing to a different database has to be instrumented throughout code and can be tedious and error prone. The pgconnection.route context manager can route any database operations to a different database, even if it’s an external management command that has not been instrumented to use a different database.

The documentation has examples of how to use django-pgconnection.

Documentation

View the django-pgconnection docs here.

Installation

Install django-pgconnection with:

pip3 install django-pgconnection

After this, add pgconnection to the INSTALLED_APPS setting of your Django project.

In order to use connection routing and hooks, one must configure the DATABASES setting in settings.py like so:

DATABASES = pgconnection.configure({
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'mydatabase',
    }
})

Contributing Guide

For information on setting up django-pgconnection for development and contributing changes, view CONTRIBUTING.rst.

Primary Authors

  • @wesleykendall (Wes Kendall)

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

django-pgconnection-1.0.2.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

django_pgconnection-1.0.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file django-pgconnection-1.0.2.tar.gz.

File metadata

  • Download URL: django-pgconnection-1.0.2.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.4 Linux/4.15.0-1102-aws

File hashes

Hashes for django-pgconnection-1.0.2.tar.gz
Algorithm Hash digest
SHA256 1c012e789cd65bee1d514de6a4b3f90c888e599c3c2be195e7bb3627923bb7f3
MD5 dec8cc3f04a015f2e0afc62b682fa00a
BLAKE2b-256 c7d825b81a2017be4ae497ff619cdfaf9e1b21dfc548743462dde2451558374a

See more details on using hashes here.

Provenance

File details

Details for the file django_pgconnection-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_pgconnection-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 51ea5943faaa4aa4a2f953586b925ecddec852b009c004ee0b5de93d5ae162f7
MD5 93e3a8d5dffd54fa2ef2e5dcd12a4efb
BLAKE2b-256 ff9bbfe0bac66796011f4d99b845c7dc2ddb68faf62421df4aff1b215e5e4b6b

See more details on using hashes here.

Provenance

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