diff options
author | Matthew Wild <mwild1@gmail.com> | 2020-03-11 16:29:57 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2020-03-11 16:29:57 +0000 |
commit | 81f5c3e319792bec5d53c30334f3f54537aeb32b (patch) | |
tree | 7730ad7cccd994ed8c798b9efb66cd997347078e /core/storagemanager.lua | |
parent | e35a4db4984013d82c90bd99fa1cbb15396fa415 (diff) | |
download | prosody-81f5c3e319792bec5d53c30334f3f54537aeb32b.tar.gz prosody-81f5c3e319792bec5d53c30334f3f54537aeb32b.zip |
storagemanager: Add support for :find_key() and :delete_key() to map store shim
Diffstat (limited to 'core/storagemanager.lua')
-rw-r--r-- | core/storagemanager.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/core/storagemanager.lua b/core/storagemanager.lua index dea71733..14de1314 100644 --- a/core/storagemanager.lua +++ b/core/storagemanager.lua @@ -167,6 +167,39 @@ local map_shim_mt = { return self.keyval_store:set(username, current); end; remove = {}; + find_key = function (self, key) + if type(key) ~= "string" or key == "" then + return nil, "find_key only supports non-empty string keys"; + end + local ret; + for username in self.keyval_store:users() do + local key_data = self:get(username, key); + if key_data then + if not ret then + ret = {}; + end + ret[username] = key_data; + end + end + return ret; + end; + delete_key = function (self, key) + if type(key) ~= "string" or key == "" then + return nil, "delete_key only supports non-empty string keys"; + end + local data = { [key] = self.remove }; + local last_err; + for username in self.keyval_store:users() do + local ok, err = self:set_keys(username, data); + if not ok then + last_err = err; + end + end + if last_err then + return nil, last_err; + end + return true; + end; }; } |