tkp.db.database
– Database connection interface¶
-
class
tkp.db.database.
DBExceptions
(engine)[source]¶ This provides an engine-agnostic wrapper around the exceptions that can the thrown by the database layer: we can refer to eg DBExcetions(engine).Error rather than <engine specific module>.Error.
We handle both the PEP-0249 exceptions as provided by the DB engine, and add our own as necessary.
-
class
tkp.db.database.
Database
(**kwargs)[source]¶ An object representing a database connection.
-
connection
¶ The database connection, will be created if it doesn’t exists.
This is a property to be backwards compatible with the rest of TKP.
Returns: a database connection
-
-
tkp.db.database.
sanitize_db_inputs
(params)[source]¶ Replace values in params with alternatives suitable for database insertion.
That includes:
- Convert numpy.floating types into Python floats;
- Convert infs into the string “Infinity”.
Parameters: params (dict/list/tuple) – (Potentially) dirty database inputs Returns: cleaned – Sanitized database inputs Return type: dict/list/tuple