Skip to content

Instantly share code, notes, and snippets.

@SpaceManiac
Created May 15, 2020 18:58
Show Gist options
  • Save SpaceManiac/e93b5b853983610ca075856ef5390bd6 to your computer and use it in GitHub Desktop.
Save SpaceManiac/e93b5b853983610ca075856ef5390bd6 to your computer and use it in GitHub Desktop.
/proc/get_connection()
var/options = list(
"host" = "127.0.0.1",
"port" = 3306,
"user" = "some_username",
"pass" = "some_password",
"db_name" = "some_dbname",
"min_threads" = 1,
"max_threads" = 5,
)
return json_decode(rustg_sql_connect_pool(json_encode(options)))["handle"]
/proc/run_query(connection, sql, arguments, async)
var/job_result_str
if (async)
var/job_id = rustg_sql_query_async(connection, sql, json_encode(arguments))
in_progress = TRUE
UNTIL((job_result_str = rustg_sql_check_query(job_id)) != RUSTG_JOB_NO_RESULTS_YET)
in_progress = FALSE
if (job_result_str == RUSTG_JOB_ERROR)
last_error = job_result_str
return FALSE
else
job_result_str = rustg_sql_query_blocking(connection, sql, json_encode(arguments))
var/result = json_decode(job_result_str)
switch (result["status"])
if ("ok")
rows = result["rows"]
affected = result["affected"]
return TRUE
if ("err")
last_error = result["data"]
return FALSE
if ("offline")
last_error = "offline"
return FALSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment