aboutsummaryrefslogtreecommitdiffstats
path: root/util/sql.lua
diff options
context:
space:
mode:
Diffstat (limited to 'util/sql.lua')
-rw-r--r--util/sql.lua16
1 files changed, 8 insertions, 8 deletions
diff --git a/util/sql.lua b/util/sql.lua
index 9d1c86ca..c897d734 100644
--- a/util/sql.lua
+++ b/util/sql.lua
@@ -4,9 +4,9 @@ local ipairs = ipairs;
local tostring = tostring;
local type = type;
local assert, pcall, debug_traceback = assert, pcall, debug.traceback;
-local xpcall = require "util.xpcall".xpcall;
+local xpcall = require "prosody.util.xpcall".xpcall;
local t_concat = table.concat;
-local log = require "util.logger".init("sql");
+local log = require "prosody.util.logger".init("sql");
local DBI = require "DBI";
-- This loads all available drivers while globals are unlocked
@@ -27,8 +27,6 @@ local function is_column(x) return getmetatable(x)==column_mt; end
local function is_index(x) return getmetatable(x)==index_mt; end
local function is_table(x) return getmetatable(x)==table_mt; end
local function is_query(x) return getmetatable(x)==query_mt; end
-local function Integer() return "Integer()" end
-local function String() return "String()" end
local function Column(definition)
return setmetatable(definition, column_mt);
@@ -99,6 +97,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 +225,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 +367,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 {
@@ -374,8 +376,6 @@ return {
is_index = is_index;
is_table = is_table;
is_query = is_query;
- Integer = Integer;
- String = String;
Column = Column;
Table = Table;
Index = Index;