aboutsummaryrefslogtreecommitdiffstats
path: root/util/sql.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-01-30 00:38:26 +0100
committerKim Alvefur <zash@zash.se>2023-01-30 00:38:26 +0100
commit0147b972e079bffb40160041de78ec50c5a1bdba (patch)
tree5ef5ca70fd4f51dcfc2ec6c2036868bca8d714e4 /util/sql.lua
parentdc958f1e40eef23f6aed6eba17c30f3b880b3c08 (diff)
downloadprosody-0147b972e079bffb40160041de78ec50c5a1bdba.tar.gz
prosody-0147b972e079bffb40160041de78ec50c5a1bdba.zip
mod_storage_sql: Record connection to database as module status
Allows retrieving this in e.g. a health reporting module Thanks pfak
Diffstat (limited to 'util/sql.lua')
-rw-r--r--util/sql.lua8
1 files changed, 6 insertions, 2 deletions
diff --git a/util/sql.lua b/util/sql.lua
index 9d1c86ca..623d4ed4 100644
--- a/util/sql.lua
+++ b/util/sql.lua
@@ -99,6 +99,9 @@ end
function engine:onconnect() -- luacheck: ignore 212/self
-- Override from create_engine()
end
+function engine:ondisconnect() -- luacheck: ignore 212/self
+ -- Override from create_engine()
+end
function engine:prepquery(sql)
if self.params.driver == "MySQL" then
@@ -224,6 +227,7 @@ function engine:transaction(...)
if not conn or not conn:ping() then
log("debug", "Database connection was closed. Will reconnect and retry.");
self.conn = nil;
+ self:ondisconnect();
log("debug", "Retrying SQL transaction [%s]", (...));
ok, ret, b, c = self:_transaction(...);
log("debug", "SQL transaction retry %s", ok and "succeeded" or "failed");
@@ -365,8 +369,8 @@ local function db2uri(params)
};
end
-local function create_engine(_, params, onconnect)
- return setmetatable({ url = db2uri(params), params = params, onconnect = onconnect }, engine_mt);
+local function create_engine(_, params, onconnect, ondisconnect)
+ return setmetatable({ url = db2uri(params); params = params; onconnect = onconnect; ondisconnect = ondisconnect }, engine_mt);
end
return {