comparison mod_storage_gdbm/mod_storage_gdbm.lua @ 1630:0fcd63818aa1

mod_storage_gdbm: Make write operation delete data when passed 'nil' as value instead of storing a literal "nil" string
author Kim Alvefur <zash@zash.se>
date Wed, 25 Mar 2015 17:39:29 +0100
parents 36eb0dbea7ba
children 98427ed3d53f
comparison
equal deleted inserted replaced
1629:36eb0dbea7ba 1630:0fcd63818aa1
40 40
41 local keyval = {}; 41 local keyval = {};
42 local keyval_mt = { __index = keyval, suffix = ".db" }; 42 local keyval_mt = { __index = keyval, suffix = ".db" };
43 43
44 function keyval:set(user, value) 44 function keyval:set(user, value)
45 local ok, err = g_set(self._db, user or "@", serialize(value)); 45 if type(value) == "table" and next(value) == nil then
46 value = nil;
47 end
48 if value ~= nil then
49 value = serialize(value);
50 end
51 local ok, err = (value and g_set or g_del)(self._db, user or "@", value);
46 if not ok then return nil, err; end 52 if not ok then return nil, err; end
47 return true; 53 return true;
48 end 54 end
49 55
50 function keyval:get(user) 56 function keyval:get(user)