This commit is contained in:
a-ill
2023-07-21 17:38:02 +03:00
parent fb705bab7c
commit ccd97c1095
12 changed files with 121 additions and 19 deletions

View File

@@ -6,14 +6,24 @@ using DataFrames
export exist_in_table, insert_into_table, update_table, select_from_table, add_foreign_key
options = SearchLight.Configuration.read_db_connection_data("db/connection.yml")
conn = SearchLight.connect(options)
function format(x)
if (x isa String) || (x isa Symbol)
return string("'",x,"'")
elseif (isnothing(x))
return "NULL"
else
return x
end
end
function insert_into_table(table_name,dict_values)
names_string = join(keys(dict_values),", ")
vals_raw = values(dict_values)
vals = map(x -> (x isa String) || (x isa Symbol) ? string("'",x,"'") : x,vals_raw)
vals = map(x -> format(x),vals_raw)
vals_string = join(values(vals),", ")
query = "INSERT INTO $table_name ($names_string) VALUES ($vals_string)"
SearchLight.query(query)