diff options
author | Kim Alvefur <zash@zash.se> | 2023-01-30 00:38:26 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2023-01-30 00:38:26 +0100 |
commit | 0147b972e079bffb40160041de78ec50c5a1bdba (patch) | |
tree | 5ef5ca70fd4f51dcfc2ec6c2036868bca8d714e4 /util/sql.lua | |
parent | dc958f1e40eef23f6aed6eba17c30f3b880b3c08 (diff) | |
download | prosody-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.lua | 8 |
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 { |