aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_storage_sql2.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2014-09-11 01:17:56 +0200
committerKim Alvefur <zash@zash.se>2014-09-11 01:17:56 +0200
commit43df3959ab0c8801cb39c1d7eba96af8a3785064 (patch)
tree147e215854eea3b4657112876b5c45863c73acc8 /plugins/mod_storage_sql2.lua
parentf41908a42c7e4f8397b52536e5e32c771b07a096 (diff)
parent534a115ec7aff123fa3358c500554d02b247e4a8 (diff)
downloadprosody-43df3959ab0c8801cb39c1d7eba96af8a3785064.tar.gz
prosody-43df3959ab0c8801cb39c1d7eba96af8a3785064.zip
Merge 0.10->trunk
Diffstat (limited to 'plugins/mod_storage_sql2.lua')
-rw-r--r--plugins/mod_storage_sql2.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/plugins/mod_storage_sql2.lua b/plugins/mod_storage_sql2.lua
index 0531c905..e5357416 100644
--- a/plugins/mod_storage_sql2.lua
+++ b/plugins/mod_storage_sql2.lua
@@ -216,6 +216,39 @@ function keyval_store:users()
return iterator(result);
end
+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.__index = archive_store
function archive_store:append(username, key, when, with, value)
@@ -341,6 +374,7 @@ end
local stores = {
keyval = keyval_store;
+ map = map_store;
archive = archive_store;
};