Software /
code /
prosody
Changeset
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 |
parents | 10678:c9251d74a112 |
children | 10680:19692fc5c106 |
files | core/storagemanager.lua spec/core_storagemanager_spec.lua |
diffstat | 2 files changed, 37 insertions(+), 7 deletions(-) [+] |
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; }; }
--- a/spec/core_storagemanager_spec.lua Wed Mar 11 16:07:36 2020 +0000 +++ b/spec/core_storagemanager_spec.lua Wed Mar 11 16:29:57 2020 +0000 @@ -62,9 +62,6 @@ sm.initialize_host(test_host); assert(mm.load(test_host, "storage_"..backend_config.storage)); - local sql_it = backend_config.sql and it or pending; - - describe("key-value stores", function () -- These tests rely on being executed in order, disable any order -- randomization for this block @@ -116,7 +113,7 @@ assert.equal("bar", store:get("user9999", "foo")); end); - sql_it("may find all users with a specific key", function () + it("may find all users with a specific key", function () assert.is_function(store.find_key); assert(store:set("user9999b", "bar", "bar")); assert(store:set("user9999c", "foo", "blah")); @@ -125,7 +122,7 @@ assert.same({ user9999 = "bar", user9999c = "blah" }, ret); end); - sql_it("rejects empty or non-string keys to find_key", function () + it("rejects empty or non-string keys to find_key", function () assert.is_function(store.find_key); do local ret, err = store:find_key(""); @@ -139,7 +136,7 @@ end end); - sql_it("rejects empty or non-string keys to delete_key", function () + it("rejects empty or non-string keys to delete_key", function () assert.is_function(store.delete_key); do local ret, err = store:delete_key(""); @@ -153,7 +150,7 @@ end end); - sql_it("may delete all instances of a specific key", function () + it("may delete all instances of a specific key", function () assert.is_function(store.delete_key); assert(store:set("user9999b", "foo", "hello"));