From 1da9cde6aed4d2dac15e97120607ee80aa84672d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 19 Feb 2016 19:22:18 +0100 Subject: mod_storage_sql: Fix setting value to false in map store --- plugins/mod_storage_sql.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 34fcacee..6efa676c 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -148,7 +148,8 @@ function map_store:get(username, key) 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() -- cgit v1.2.3 From c9d425731dd0f2c07d1b884c5529f81cfbf4f63c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 21 Feb 2016 14:53:19 +0100 Subject: mod_storage_sql: Share SQL connections with same parameters across VirtualHosts (fixes #576) --- plugins/mod_storage_sql.lua | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 6efa676c..50d34a23 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -449,19 +449,25 @@ 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("info", "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 -- cgit v1.2.3