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 | a503b527a2e03270868ae48a53ec452d5da9a233cd7aaa8e8cef0f2d20adb4bf |
|
MD5 | 00040c3c1523413ff8b030b096c64519 |
|
BLAKE2b-256 | fa090dc99f79ff0efc580ade46b48778449b858b9b85bf06f2d5acdf91c9f040 |
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7c46cd8d22d5dfe6a904fab6cb003471905d308bc79a54960a13cfbd3ca60db |
|
MD5 | 0824d9a82a645e39c8991be4e423eb9f |
|
BLAKE2b-256 | ed792e718af6d1ef2fe5adbadc1c7a9346c8df8f63dda84788fec8d4ef9f3769 |