diff options
author | Hans Hagen <pragma@wxs.nl> | 2023-03-06 15:17:09 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2023-03-06 15:17:09 +0100 |
commit | e12b4fabeb0ce3ce6d256b54250cf38a8f940561 (patch) | |
tree | b574cb45fe8a416e60c912a8e2d754abdad3b63c /tex/context/base/mkiv/util-sql.lua | |
parent | 23b5ef45e7939a00addff726d02d6c29243177af (diff) | |
download | context-e12b4fabeb0ce3ce6d256b54250cf38a8f940561.tar.gz |
2023-03-06 14:47:00
Diffstat (limited to 'tex/context/base/mkiv/util-sql.lua')
-rw-r--r-- | tex/context/base/mkiv/util-sql.lua | 29 |
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") |