Skip to content
Snippets Groups Projects
Commit e4027c84 authored by Riccardo Boero's avatar Riccardo Boero :innocent:
Browse files

Added method to quickly check if table in database

parent 3e9bbecc
No related branches found
No related tags found
No related merge requests found
......@@ -42,6 +42,6 @@ module FACTResultsIO
export get_connection, close_connection
include("manifestIO.jl")
export get_table, write_table, overwrite_table
export get_table, write_table, overwrite_table, does_table_exist_for_method
end
......@@ -78,6 +78,36 @@ function write_table(conn::MySQL.Connection, method_name::String, arguments_stri
end
end
"""
does_table_exist_for_method(conn::MySQL.Connection, method_name::String, arguments_string::String, arguments::Dict) -> Bool
Check if a specific table exists in the database based on a method name, an argument string, and additional arguments. This function queries a manifest (or similar mapping) that links method names and their arguments to database table names.
# Arguments
- `conn::MySQL.Connection`: The MySQL database connection.
- `method_name::String`: The name of the method to check. This is a key or identifier used to search the manifest.
- `arguments_string::String`: A string representation of arguments or conditions. Its format and usage can vary depending on the manifest's structure.
- `arguments::Dict`: A dictionary of arguments providing additional search criteria or parameters for the manifest query.
# Returns
`Bool`: Returns `true` if the table exists for the specified method and arguments, based on the manifest's mapping. Returns `false` if no such table is found.
# Example
To check if a table exists for a method 'getEmployeeData' with arguments indicating a permanent type in the engineering department, you would call the function as follows:
- Initialize your MySQL connection as `conn`.
- Set `method_name` to "getEmployeeData".
- Define `arguments_string` as "type=permanent".
- Create a dictionary `arguments` with `{"department" => "engineering"}`.
- Call `does_table_exist_for_method(conn, method_name, arguments_string, arguments)` to check for the table's existence.
# Notes
This function relies on the implementation of `find_table_name_in_manifest`, which must query a manifest or similar structure to find the corresponding table name based on the provided method name and arguments. The manifest structure and query logic are assumed to be predefined.
"""
function does_table_exist_for_method(conn::MySQL.Connection, method_name::String, arguments_string::String, arguments::Dict)
table_str = find_table_name_in_manifest(conn, method_name, arguments_string, arguments)
return table_str != ""
end
"""
overwrite_table(conn::MySQL.Connection, method_name::String, arguments_string::String, arguments::Dict, results::DataFrame)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment