return result;
end
function map_store:set(username, key, data)
- return self:set_keys(username, { [key] = data or self.remove });
+ if data == nil then data = self.remove; end
+ return self:set_keys(username, { [key] = data });
end
function map_store:set_keys(username, keydatas)
local ok, result = engine:transaction(function()
end
sql_query = sql_query:format(t_concat(where, " AND "), query.reverse and "DESC" or "ASC", query.limit and " LIMIT ?" or "");
- module:log("debug", sql_query);
return engine:select(sql_query, unpack(args));
end);
if not ok then return ok, result end
archive_where(query, args, where);
archive_where_id_range(query, args, where);
sql_query = sql_query:format(t_concat(where, " AND "));
- module:log("debug", sql_query);
return engine:delete(sql_query, unpack(args));
end);
end
function module.load()
if prosody.prosodyctl then return; end
+ local engines = module:shared("/*/sql/connections");
local params = normalize_params(module:get_option("sql", default_params));
- engine = sql:create_engine(params, function (engine)
- if module:get_option("sql_manage_tables", true) then
- -- Automatically create table, ignore failure (table probably already exists)
- -- FIXME: we should check in information_schema, etc.
- create_table();
- -- Check whether the table needs upgrading
- if upgrade_table(params, false) then
- module:log("error", "Old database format detected. Please run: prosodyctl mod_%s upgrade", module.name);
- return false, "database upgrade needed";
+ engine = engines[sql.db2uri(params)];
+ if not engine then
+ module:log("debug", "Creating new engine");
+ engine = sql:create_engine(params, function (engine)
+ if module:get_option("sql_manage_tables", true) then
+ -- Automatically create table, ignore failure (table probably already exists)
+ -- FIXME: we should check in information_schema, etc.
+ create_table();
+ -- Check whether the table needs upgrading
+ if upgrade_table(params, false) then
+ module:log("error", "Old database format detected. Please run: prosodyctl mod_%s upgrade", module.name);
+ return false, "database upgrade needed";
+ end
end
- end
- end);
+ end);
+ engines[sql.db2uri(params)] = engine;
+ end
module:provides("storage", driver);
end