aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2015-12-03 15:43:02 +0000
committerMatthew Wild <mwild1@gmail.com>2015-12-03 15:43:02 +0000
commitfa325412c7772617f9212c3022ff55bacc872e3a (patch)
tree1d8957cc4cb07df8aa0b11e80e6d612e935a3e32 /plugins
parent5656b525d3b72b09964fe9fbc2b70ceda54ab66b (diff)
parent5c6a61d2e7cd76bc7d7b050839eb5da61feda661 (diff)
downloadprosody-fa325412c7772617f9212c3022ff55bacc872e3a.tar.gz
prosody-fa325412c7772617f9212c3022ff55bacc872e3a.zip
Merge 0.10->trunk
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_storage_sql.lua36
1 files changed, 35 insertions, 1 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index 7695e15d..adf9f9b6 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -107,7 +107,7 @@ function keyval_store:get(username)
module:log("error", "Unable to read from database %s store for %s: %s", store, username or "<host>", result);
return nil, result;
end
- return result;
+ return result;
end
function keyval_store:set(username, data)
user,store = username,self.store;
@@ -125,6 +125,39 @@ end
--- Archive store API
+local map_store = {};
+map_store.__index = map_store;
+function map_store:get(username, key)
+ local ok, result = engine:transaction(function()
+ if type(key) == "string" and key ~= "" then
+ for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, username or "", self.store, key) do
+ return deserialize(row[1], row[2]);
+ end
+ else
+ error("TODO: non-string keys");
+ end
+ end);
+ if not ok then return nil, result; end
+ return result;
+end
+function map_store:set(username, key, data)
+ local ok, result = engine:transaction(function()
+ if type(key) == "string" and key ~= "" then
+ engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?",
+ host, username or "", self.store, key);
+ if data ~= nil then
+ local t, value = assert(serialize(data));
+ engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, username or "", self.store, key, t, value);
+ end
+ else
+ error("TODO: non-string keys");
+ end
+ return true;
+ end);
+ if not ok then return nil, result; end
+ return result;
+end
+
local archive_store = {}
archive_store.caps = {
total = true;
@@ -253,6 +286,7 @@ end
local stores = {
keyval = keyval_store;
+ map = map_store;
archive = archive_store;
};