relstorage.adapters.drivers – Helpers for drivers

Helpers for drivers

exception DriverNotImportableError(driver_name, driver_options=None, reason=None)[source]

Bases: relstorage.adapters.interfaces.DriverNotAvailableError, ImportError

When the module can’t be imported.

class AbstractModuleDriver[source]

Bases: object

Base implementation of a driver, based on a module, as used in DBAPI.

Subclasses must provide:

  • MODULE_NAME property.

  • __name__ property

  • Implementation of get_driver_module; this should import the module at runtime.

exception DriverNotAvailableError(driver_name, driver_options=None, reason=None)

Bases: Exception

Raised when a requested driver isn’t available.

driver_name = None

The name of the requested driver

driver_options = None

The IDBDriverOptions that was asked for the driver.

reason = None

The underlying reason string, for example, from an import error if such is available.


Default implementation; does nothing.

enter_critical_phase_until_transaction_end(connection, cursor)[source]

Default implementation; does nothing.

exit_critical_phase(connection, cursor)[source]

Default implementation; does nothing.


Import and return the driver module.

is_in_critical_phase(connection, cursor)[source]

Default implementation; returns a false value.


Exceptions here are ignored, we don’t know what state the cursor is in.


Can this module be used on PyPy?


The name of the DB-API module to import.


Priority of this driver, when available. Lower is better. (That is, first choice should have value 1, and second choice value 2, and so on.)


Priority of this driver when running on PyPy. Lower is better.


Set this to false if your subclass can do static checks at import time to determine it should not be used. Helpful for things like Python version detection.

STRICT = False

Class attribute. If set to a true value (not the default), ask the underlying driver to work in as strict a mode as possible when it comes to detecting programming errors.

Typically set by tests. Most drivers do not have a stricter mode that can be enabled.

cursor_arraysize = 1024

The size we request cursor’s from our cursor() method to fetch from fetchmany and (hopefully) iteration (which is a DB-API extension. We default to 1024, but the environment variable RS_CURSOR_ARRAYSIZE can be set to an int to change this default. Individual drivers might choose a different default.

casefold(self, /)

Return a version of the string suitable for caseless comparisons.

implement_db_driver_options(name, *driver_modules)[source]

Helper function to be called at a module scope to make it implement IDBDriverOptions.

  • name (str) – The value of __name__.

  • driver_modules – Each of these names a module that has one or more implementations of IDBDriver in it, as named in their __all__ attribute.