Db

class baboossh.Db[source]

A singleton handling the database connection

This class allows the use of a single sqlite connection for earch thread

__init__()

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__

Initialize self.

build(workspace)

Create the databases and the tables for a new Workspace

close()

Closes the connection for the current Thread

connect(workspace)

Open the connection to the database for a Workspace

get()

Returns the database connection for the current thread

classmethod build(workspace)[source]

Create the databases and the tables for a new Workspace

Parameters

workspace (str) – the workspace’s name

classmethod close()[source]

Closes the connection for the current Thread

classmethod connect(workspace)[source]

Open the connection to the database for a Workspace

If this function is called from the main thread, it closes existing sqlite connections and opens a new one. Else, if a connection isn’t already open for the current thread, it opens the connection.

Parameters

workspace (str) – the name of the Workspace to open

Raises

ValueError – raised if the database file doesn’t exist

classmethod get()[source]

Returns the database connection for the current thread

If the current thread isn’t the main and no connection is already opened, opens a new one and returns it

Returns

An open sqlite3.Connection