tkp.db.database – Database connection interface

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

An object representing a database connection.


close the connection if open


connect to the configured database

Parameters:check (bool) – check if schema version is correct

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

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

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