From 81f5c3e319792bec5d53c30334f3f54537aeb32b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 11 Mar 2020 16:29:57 +0000 Subject: storagemanager: Add support for :find_key() and :delete_key() to map store shim --- core/storagemanager.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'core/storagemanager.lua') 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; }; } -- cgit v1.2.3 From cb6148d155ea02a68e40b8afb5861451750499ad Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 11 Mar 2020 16:32:41 +0000 Subject: storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all() --- core/storagemanager.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'core/storagemanager.lua') diff --git a/core/storagemanager.lua b/core/storagemanager.lua index 14de1314..856acad3 100644 --- a/core/storagemanager.lua +++ b/core/storagemanager.lua @@ -167,9 +167,9 @@ local map_shim_mt = { return self.keyval_store:set(username, current); end; remove = {}; - find_key = function (self, key) + get_all = function (self, key) if type(key) ~= "string" or key == "" then - return nil, "find_key only supports non-empty string keys"; + return nil, "get_all only supports non-empty string keys"; end local ret; for username in self.keyval_store:users() do @@ -183,9 +183,9 @@ local map_shim_mt = { end return ret; end; - delete_key = function (self, key) + delete_all = function (self, key) if type(key) ~= "string" or key == "" then - return nil, "delete_key only supports non-empty string keys"; + return nil, "delete_all only supports non-empty string keys"; end local data = { [key] = self.remove }; local last_err; -- cgit v1.2.3