aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2014-08-07 12:16:16 -0400
committerdaurnimator <quae@daurnimator.com>2014-08-07 12:16:16 -0400
commit1b133aa8a0cb4f862ffda75ce24f9fd45e2ddef2 (patch)
treeb71cb33ab2122202187f40df67a8863f63613a8d /plugins
parentea09a4527815cec3d42583dc3f751662d861b9dd (diff)
downloadprosody-1b133aa8a0cb4f862ffda75ce24f9fd45e2ddef2.tar.gz
prosody-1b133aa8a0cb4f862ffda75ce24f9fd45e2ddef2.zip
plugins/mod_storage_sql2: Add map store support
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_storage_sql2.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/plugins/mod_storage_sql2.lua b/plugins/mod_storage_sql2.lua
index 0531c905..ce21d368 100644
--- a/plugins/mod_storage_sql2.lua
+++ b/plugins/mod_storage_sql2.lua
@@ -216,6 +216,40 @@ function keyval_store:users()
return iterator(result);
end
+local map_store = {};
+map_store.__index = map_store;
+function map_store:get(username, key)
+ return engine:transaction(function()
+ if type(key) == "string" and key ~= "" then
+ local iter, state, first = engine:select("SELECT * FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?",
+ host, username, self.store, key or "");
+ local row = iter(state, first);
+ if row then
+ return deserialize(row.type, row.value);
+ else
+ return nil;
+ end
+ else
+ error("TODO: non-string keys");
+ end
+ end);
+end
+function map_store:set(username, key, data)
+ return engine:transaction(function()
+ if data == nil then
+ engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?",
+ host, username, self.store, key or "");
+ elseif type(key) == "string" and key ~= "" then
+ local t, value = assert(serialize(data));
+ engine:update("UPDATE `prosody` SET `type`=?, `value`=? WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?",
+ t, value, host, username, self.store, key);
+ else
+ error("TODO: non-string keys");
+ end
+ return true;
+ end);
+end
+
local archive_store = {}
archive_store.__index = archive_store
function archive_store:append(username, key, when, with, value)
@@ -341,6 +375,7 @@ end
local stores = {
keyval = keyval_store;
+ map = map_store;
archive = archive_store;
};