tkp.db.database – Database connection interface

class tkp.db.database.Database(**kwargs)[source]

An object representing a database connection.

close()[source]

close the connection if open

connect(check=False)[source]

connect to the configured database

Parameters:check (bool) – check if schema version is correct
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
vacuum(table)[source]

Force a vacuum on a table, which removes dead rows. (Postgres only)

Normally the auto vacuum process does this for you, but in some cases (for example when the table receives many insert and deletes) manual vacuuming is necessary for performance reasons.

Parameters:table – name of the table in the database you want to vacuum
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:Sanitized database inputs
Return type:cleaned (dict/list/tuple)