Primary Authors
@wesleykendall (Wes Kendall)
Route postgres connections and hook into cursor execution
django-pgconnection provides primitives for overriding Postgres connection and cursor objects, making it possible to do the following:
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.
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.
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', } })
For information on setting up django-pgconnection for development and contributing changes, view CONTRIBUTING.rst.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Algorithm | Hash digest | |
---|---|---|
SHA256 | 395d82fc6ca612b8575373c317d6f1a47974dadda965e043d2704609ded12c0a |
|
MD5 | 2d8484983fc02bbaebae2e00c633e8fa |
|
BLAKE2b-256 | 4ffa507cc09eedca06e0e37dc27f77be1e19ddc2f087d3c05b0b8ded8cebc62f |
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d2dadeb8b7bdf8ac94f2a5c553f6d96c446331c1f3e930dd6fc4f194bbec90a |
|
MD5 | 5b31e2f74e468cec4c18fdf9d6d6ae1d |
|
BLAKE2b-256 | c779a767714bd196d48227480f2e5180dfdf57d99a36032fec5fc97a285cee09 |