Package

pgconnection.check()[source]

Raises RuntimeError if pgconnection is not configured correctly

pgconnection.configure(databases)[source]

Given a database configuration dictionary, return a copy that is configured to use the pgconnection database cursor.

Parameters

databases (Dict[dict]) – A dictionary of database configurations (e.g. settings.DATABASES)

Returns

A copy of the dictionary of databases configured to

use the pgconnection cursor.

Return type

Dict[dict]

pgconnection.connect_pre_execute_hook(hook_func, using='default')[source]

Connects a hook function that will be executed before any SQL

Parameters
  • hook_func (func) – The hook function that takes the SQL, its variables, and the cursor as arguments. It must return a tuple of the modified SQL and vars or None.

  • using (str, default='default') – The alias of the database. Must be present in settings.DATABASES

pgconnection.disconnect_pre_execute_hook(hook_func, using='default')[source]

Disconnects a hook function that will be executed before any SQL

Parameters
  • hook_func (func) – The hook function that takes the SQL, its variables, and the cursor as arguments. It must return a tuple of the modified SQL and vars.

  • using (str, default='default') – The alias of the database. Must be present in settings.DATABASES

pgconnection.pre_execute_hook(hook_func, using='default')[source]

A context manager to run code with a connected pre_execute hook. See connect_pre_execute_hook for more information about the arguments.

pgconnection.route(destination, using='default')[source]

Route connections to another database.

If the source database is configured to use pgconnection cursors, an additional hook is provisioned to ensure that no queries happen on the source database

Parameters
  • destination (dict) – Database configuration dictionary to be routed.

  • using (str, default='default') – The source database to use when routing to another database. Defaults to the default database.