Comparison

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
comparison
equal deleted inserted replaced
10678:c9251d74a112 10679:b50b1eae711c
165 current[k] = v; 165 current[k] = v;
166 end 166 end
167 return self.keyval_store:set(username, current); 167 return self.keyval_store:set(username, current);
168 end; 168 end;
169 remove = {}; 169 remove = {};
170 find_key = function (self, key)
171 if type(key) ~= "string" or key == "" then
172 return nil, "find_key only supports non-empty string keys";
173 end
174 local ret;
175 for username in self.keyval_store:users() do
176 local key_data = self:get(username, key);
177 if key_data then
178 if not ret then
179 ret = {};
180 end
181 ret[username] = key_data;
182 end
183 end
184 return ret;
185 end;
186 delete_key = function (self, key)
187 if type(key) ~= "string" or key == "" then
188 return nil, "delete_key only supports non-empty string keys";
189 end
190 local data = { [key] = self.remove };
191 local last_err;
192 for username in self.keyval_store:users() do
193 local ok, err = self:set_keys(username, data);
194 if not ok then
195 last_err = err;
196 end
197 end
198 if last_err then
199 return nil, last_err;
200 end
201 return true;
202 end;
170 }; 203 };
171 } 204 }
172 205
173 local open; -- forward declaration 206 local open; -- forward declaration
174 207