Changeset

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 1629:36eb0dbea7ba
children 1631:98427ed3d53f
files mod_storage_gdbm/mod_storage_gdbm.lua
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_storage_gdbm/mod_storage_gdbm.lua	Wed Mar 25 17:37:52 2015 +0100
+++ b/mod_storage_gdbm/mod_storage_gdbm.lua	Wed Mar 25 17:39:29 2015 +0100
@@ -42,7 +42,13 @@
 local keyval_mt = { __index = keyval, suffix = ".db" };
 
 function keyval:set(user, value)
-	local ok, err = g_set(self._db, user or "@", serialize(value));
+	if type(value) == "table" and next(value) == nil then
+		value = nil;
+	end
+	if value ~= nil then
+		value = serialize(value);
+	end
+	local ok, err = (value and g_set or g_del)(self._db, user or "@", value);
 	if not ok then return nil, err; end
 	return true;
 end