aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2020-03-11 15:57:53 +0000
committerMatthew Wild <mwild1@gmail.com>2020-03-11 15:57:53 +0000
commitd669797472629e4876d295a67f76ac045ddb6d30 (patch)
tree99a0e35b92bc4513d2ecd229007c78243be886ad /plugins
parentd56fa1f1c1a325bb86084ab71fdd3a77d6db3a61 (diff)
downloadprosody-d669797472629e4876d295a67f76ac045ddb6d30.tar.gz
prosody-d669797472629e4876d295a67f76ac045ddb6d30.zip
mod_storage_sql: Add map_store:find_key() and map_store:delete_key() (+ tests)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_storage_sql.lua44
1 files changed, 44 insertions, 0 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index 4a2f0d90..a75b832d 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -230,6 +230,50 @@ function map_store:set_keys(username, keydatas)
return result;
end
+function map_store:find_key(key)
+ if type(key) ~= "string" or key == "" then
+ return nil, "find_key only supports non-empty string keys";
+ end
+ local ok, result = engine:transaction(function()
+ local query = [[
+ SELECT "user", "type", "value"
+ FROM "prosody"
+ WHERE "host"=? AND "store"=? AND "key"=?
+ ]];
+
+ local data;
+ for row in engine:select(query, host, self.store, key) do
+ local key_data, err = deserialize(row[2], row[3]);
+ assert(key_data ~= nil, err);
+ if data == nil then
+ data = {};
+ end
+ data[row[1]] = key_data;
+ end
+
+ return data;
+
+ end);
+ if not ok then return nil, result; end
+ return result;
+end
+
+function map_store:delete_key(key)
+ if type(key) ~= "string" or key == "" then
+ return nil, "delete_key only supports non-empty string keys";
+ end
+ local ok, result = engine:transaction(function()
+ local delete_sql = [[
+ DELETE FROM "prosody"
+ WHERE "host"=? AND "store"=? AND "key"=?;
+ ]];
+ engine:delete(delete_sql, host, self.store, key);
+ return true;
+ end);
+ if not ok then return nil, result; end
+ return result;
+end
+
local archive_store = {}
archive_store.caps = {
total = true;