mirror of
https://github.com/bjc/prosody.git
synced 2025-04-03 21:27:38 +03:00
storagemanager, mod_storage_sql: Rename methods to :get_all() and :delete_all()
This commit is contained in:
parent
81f5c3e319
commit
cb6148d155
3 changed files with 20 additions and 20 deletions
|
@ -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;
|
||||
|
|
|
@ -230,9 +230,9 @@ function map_store:set_keys(username, keydatas)
|
|||
return result;
|
||||
end
|
||||
|
||||
function map_store:find_key(key)
|
||||
function map_store:get_all(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 ok, result = engine:transaction(function()
|
||||
local query = [[
|
||||
|
@ -258,9 +258,9 @@ function map_store:find_key(key)
|
|||
return result;
|
||||
end
|
||||
|
||||
function map_store:delete_key(key)
|
||||
function map_store:delete_all(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 ok, result = engine:transaction(function()
|
||||
local delete_sql = [[
|
||||
|
|
|
@ -114,47 +114,47 @@ describe("storagemanager", function ()
|
|||
end);
|
||||
|
||||
it("may find all users with a specific key", function ()
|
||||
assert.is_function(store.find_key);
|
||||
assert.is_function(store.get_all);
|
||||
assert(store:set("user9999b", "bar", "bar"));
|
||||
assert(store:set("user9999c", "foo", "blah"));
|
||||
local ret, err = store:find_key("foo");
|
||||
local ret, err = store:get_all("foo");
|
||||
assert.is_nil(err);
|
||||
assert.same({ user9999 = "bar", user9999c = "blah" }, ret);
|
||||
end);
|
||||
|
||||
it("rejects empty or non-string keys to find_key", function ()
|
||||
assert.is_function(store.find_key);
|
||||
it("rejects empty or non-string keys to get_all", function ()
|
||||
assert.is_function(store.get_all);
|
||||
do
|
||||
local ret, err = store:find_key("");
|
||||
local ret, err = store:get_all("");
|
||||
assert.is_nil(ret);
|
||||
assert.is_not_nil(err);
|
||||
end
|
||||
do
|
||||
local ret, err = store:find_key(true);
|
||||
local ret, err = store:get_all(true);
|
||||
assert.is_nil(ret);
|
||||
assert.is_not_nil(err);
|
||||
end
|
||||
end);
|
||||
|
||||
it("rejects empty or non-string keys to delete_key", function ()
|
||||
assert.is_function(store.delete_key);
|
||||
it("rejects empty or non-string keys to delete_all", function ()
|
||||
assert.is_function(store.delete_all);
|
||||
do
|
||||
local ret, err = store:delete_key("");
|
||||
local ret, err = store:delete_all("");
|
||||
assert.is_nil(ret);
|
||||
assert.is_not_nil(err);
|
||||
end
|
||||
do
|
||||
local ret, err = store:delete_key(true);
|
||||
local ret, err = store:delete_all(true);
|
||||
assert.is_nil(ret);
|
||||
assert.is_not_nil(err);
|
||||
end
|
||||
end);
|
||||
|
||||
it("may delete all instances of a specific key", function ()
|
||||
assert.is_function(store.delete_key);
|
||||
assert.is_function(store.delete_all);
|
||||
assert(store:set("user9999b", "foo", "hello"));
|
||||
|
||||
assert(store:delete_key("bar"));
|
||||
assert(store:delete_all("bar"));
|
||||
-- Ensure key was deleted
|
||||
do
|
||||
local ret, err = store:get("user9999b", "bar");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue