Software /
code /
prosody
Diff
core/storagemanager.lua @ 10679:b50b1eae711c
storagemanager: Add support for :find_key() and :delete_key() to map store shim
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 11 Mar 2020 16:29:57 +0000 |
parent | 8717:9ddd0fbbe53a |
child | 10680:19692fc5c106 |
line wrap: on
line diff
--- a/core/storagemanager.lua Wed Mar 11 16:07:36 2020 +0000 +++ b/core/storagemanager.lua Wed Mar 11 16:29:57 2020 +0000 @@ -167,6 +167,39 @@ 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; }; }