database

This module’s scope covers database operations.

class tuna.io.database.database[source]

This class’ responsibilities are creating and maintaining a connection to a system’s MySQL database. It is also the gateway through which queries are to be made.

It inherits from the threading.Thread class, and it auto-starts its thread execution. Clients are expected to use its .join ( ) method before using its results.

This module is part of the “guts” of Tuna and is not meant as a user-serviceable module.

check_mysql_connection()[source]

This method’s goal is to verify that the connection to the database manager is working.

Returns:

unnamed variable : bool
This value corresponds to the self.connection object being None or existing.
check_tables()[source]

This method’s goal is to verify that the database connected to contains the proper tables for running Tuna.

close_mysql_connection()[source]

This method’s goal is to close the connection to the database manager.

configure_tables()[source]

This method’s goal is to populate an empty database with a structure defined in self.expected_tables.

dequeue()[source]

This method’s goal is to pop the first entry on the query queue, and attempt to process it.

enqueue(data)[source]

This method’s goal is to add a request to the queue.

Parameters:

  • data : dictionary

    Must contain valid entries for the following keys: function, args and kwargs.

insert_record(table, columns_values)[source]

This method’s goal is to enqueue a request to self.insert_record_processor ( ).

Parameters:

  • table : string

    Must contain a name for a valid table on the database.

  • columns_values : dictionary

    A dictionary where keys must contain valid column identifiers for the specified table, and the dictionary values must be valid values of the type the database specifies for that column, in that table.

insert_record_processor(table, columns_values)[source]

This method’s goal is to process a insert statement in the database manager.

Parameters:

  • table : string

    Must contain a name for a valid table on the database.

  • columns_values : dictionary

    A dictionary where keys must contain valid column identifiers for the specified table, and the dictionary values must be valid values of the type the database specifies for that column, in that table.

open_mysql_connection()[source]

This method’s goal is to connect to the database manager. Which should reside on the ‘localhost’, have a database ‘tuna’ and a user ‘tuna’ that has all rights on the database ‘tuna’, using the password ‘tuna’.

process(data)[source]

This method’s goal is to process a query request.

Parameters:

  • data : dictionary

    Must contain valid entries for the following keys: function, args and kwargs.

run()[source]

This method is required by threading, which allows parallel exection in a separate thread.

This method’s goal is to connect to a MySQL daemon, verify that it has the appropriate tables and keep the connection open until the object is stopped.

select_record(table, columns_values)[source]

This method’s goal is to process a select statement in the database manager.

Parameters:

  • table : string

    Must contain a name for a valid table on the database.

  • columns_values : dictionary

    A dictionary where keys must contain valid column identifiers for the specified table, and the dictionary values must be valid values of the type the database specifies for that column, in that table.

Returns:

  • unnamed variable : list

    The same structure as returned by pymysql.cursor.fetchall ( ).

  • unnamed variable : bool

    Will be True if the connection is open, and data was retrieved without raising an exception. Otherwise, will return False.

stop()[source]

This method’s goal is to initiate a shutdown sequence of the object, which will disconnect from the MySQL daemon and stop the thread.

update_record(table, columns_values)[source]

This method’s goal is to enqueue a request to update_record_processor ( ).

Parameters:

  • table : string

    Must contain a name for a valid table on the database.

  • columns_values : dictionary

    A dictionary where keys must contain valid column identifiers for the specified table, and the dictionary values must be valid values of the type the database specifies for that column, in that table.

update_record_processor(table, columns_values)[source]

This method’s goal is to process an update statement in the database manager.

Parameters:

  • table : string

    Must contain a name for a valid table on the database.

  • columns_values : dictionary

    A dictionary where keys must contain valid column identifiers for the specified table, and the dictionary values must be valid values of the type the database specifies for that column, in that table.