working on some better persistence abstraction

This commit is contained in:
Manuel Simon Hirsig
2016-03-21 03:19:48 +01:00
parent b7539d7964
commit 0e3e7255c1
+31 -6
View File
@@ -18,15 +18,40 @@ function public.load_dataset()
return aux_datasets[dataset_key] return aux_datasets[dataset_key]
end end
function public.schema(...) function private.read(type, str)
return function(datastring) if type == 'string' then
for i=1,arg.n do return str
elseif type == 'boolean' then
return str == '1'
elseif type == 'number' then
return tonumber(str)
end
end
end function private.write(type, obj)
end, function(record) if type == 'string' then
for i=1,arg.n do return obj
elseif type == 'boolean' then
return obj and '1' or '0'
elseif type == 'number' then
return tostring(obj)
end
end
function public.schema(separator, ...)
return function(record)
local fields
local parts = Aux.util.split(record, separator)
for i=1,arg.n do
tinsert(fields, private.read(arg[i], parts[i]))
end end
return fields
end, function(fields)
local parts = {}
for i=1,arg.n do
tinsert(parts, private.write(arg[i], fields[i]))
end
return Aux.util.join(parts, '#')
end end
end end