OpenDB

class openmsimodel.db.open_db.OpenDB(database_name, private_path, output)

Bases: Runnable

OpenDB - Database Interaction Tool

This tool allows interaction with a database for managing model artifacts. It provides capabilities for loading models, executing queries, and more.

ARGUMENT_PARSER_TYPE

alias of OpenMSIModelParser

setup(database_name, private_path)

Set up the OpenDB tool.

Parameters:
  • database_name – Name of the database to connect to.

  • private_path – Path to a JSON file containing database credentials.

record_query_results(sql_results, query, name, dump=True)

Print query results and optionally save them to a CSV file.

Parameters:
  • sql_results (DataFrame) – The results of the SQL query.

  • query (str) – The SQL query that produced the results.

  • name (str) – A name to use for the output file.

  • dump (bool) – If True, save the results to a CSV file. Default is True.

Returns:

The input DataFrame (sql_results).

Return type:

DataFrame

Raises:

ValueError – If an error occurs while saving to the output file.

Examples:

Example 1:

result_df = self.load_model("example_model", "/path/to/model")
query = "SELECT * FROM data"
self.print_and_dump(result_df, query, "data_output")
list_queries()

List and display available queries along with their documentation.

classmethod get_command_line_arguments()

Get the list of argument names and the dictionary of argument names/default values to add to the argument parser

Returns:

args, a list of argument names recognized by the argument parser

Return type:

list(str)

Returns:

kwargs, a dictionary of default argument values keyed by argument names recognized by the argument parser

Return type:

dict

classmethod run_from_command_line(args=None)

Child classes should implement this function to do whatever it is they do when they run from the command line

Parameters:

args (list) – the list of arguments to send to the parser instead of getting them from sys.argv