summaryrefslogtreecommitdiff
path: root/tex/context/base/m-sql.mkiv
blob: bccfa9cb8c221c8cf707057fd2124de4f95cf577 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
%D \module
%D   [       file=m-sql,
%D        version=2012.07.12,
%D          title=\CONTEXT\ Extra Modules,
%D       subtitle=SQL,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\registerctxluafile{util-tpl}{}
\registerctxluafile{util-sql}{}

\startluacode

local sql = utilities.sql

function sql.show(specification)
    local data = specification.data
    if data and #data > 0 then
        local keys = specification.order or table.sortedkeys(data[1])
        local align = specification.align
        local template = "|"
        if type(align) == "table" then
            for i=1,#keys do
                template = template .. (align[keys[i]] or "c") .. "|"
            end
        else
            template = template .. string.rep((align or "c").. "|",#keys)
        end
        context.starttabulate { template }
        context.NC()
        for i=1,#keys do
            context(keys[i])
            context.NC()
        end
        context.NR()
        context.HL()
        for i=specification.first or 1,specification.last or #data do
            local d = data[i]
            context.NC()
            for i=1,#keys do
                context(d[keys[i]])
                context.NC()
            end
            context.NR()
        end
        context.stoptabulate()
    end
end

\stopluacode

\endinput