Software /
code /
prosody
Changeset
6961:bd76e73a20c6
Merge
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 03 Dec 2015 16:17:40 +0100 |
parents | 6960:50e2277ea05f (current diff) 6954:400badaf1fc7 (diff) |
children | 6962:2bb6586eacdd 6963:e3be91ccca05 |
files | |
diffstat | 1 files changed, 35 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_storage_sql.lua Thu Dec 03 16:17:19 2015 +0100 +++ b/plugins/mod_storage_sql.lua Thu Dec 03 16:17:40 2015 +0100 @@ -107,7 +107,7 @@ 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 @@ --- 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 @@ local stores = { keyval = keyval_store; + map = map_store; archive = archive_store; };