summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/util-sql.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/util-sql.lua')
-rw-r--r--tex/context/base/mkiv/util-sql.lua29
1 files changed, 28 insertions, 1 deletions
diff --git a/tex/context/base/mkiv/util-sql.lua b/tex/context/base/mkiv/util-sql.lua
index 55c4961f7..f729acfb9 100644
--- a/tex/context/base/mkiv/util-sql.lua
+++ b/tex/context/base/mkiv/util-sql.lua
@@ -87,12 +87,22 @@ sql.helpers = helpers
local serialize = table.fastserialize
local deserialize = table.deserialize
+local json = require("util-jsn")
+local tojson = json.tostring
+local fromjson = json.tolua
+
sql.serialize = serialize
sql.deserialize = deserialize
helpers.serialize = serialize -- bonus
helpers.deserialize = deserialize -- bonus
+sql.tojson = tojson
+sql.fromjson = fromjson
+
+helpers.tojson = tojson -- bonus
+helpers.fromjson = fromjson -- bonus
+
local defaults = { __index =
{
resultfile = "result.dat",
@@ -174,6 +184,8 @@ local function makeconverter(entries,celltemplate,wraptemplate)
assignments[#assignments+1] = format("[%q] = tab_%s[%s],",name,#converters,value)
elseif kind == "deserialize" then
assignments[#assignments+1] = format("[%q] = deserialize(%s),",name,value)
+ elseif kind == "fromjson" then
+ assignments[#assignments+1] = format("[%q] = fromjson(%s),",name,value)
elseif kind == "key" then
-- hashed instead of indexed
key = value
@@ -392,13 +404,25 @@ function sql.usedatabase(presets,datatable)
name = name or "data"
for i=1,#records do
local record = records[i]
- local data = record[name]
+ local data = record[name]
if data then
record[name] = deserialize(data)
end
end
end
end
+ local function unpackjson(records,name)
+ if records then
+ name = name or "json"
+ for i=1,#records do
+ local record = records[i]
+ local data = record[name]
+ if data then
+ record[name] = fromjson(data)
+ end
+ end
+ end
+ end
return {
usedmethod = usedmethod,
presets = preset,
@@ -408,7 +432,10 @@ function sql.usedatabase(presets,datatable)
execute = execute,
serialize = serialize,
deserialize = deserialize,
+ tojson = tojson,
+ fromjson = fromjson,
unpackdata = unpackdata,
+ unpackjson = unpackjson,
}
else
report_state("missing name in usedatabase specification")