summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/sql
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2016-09-04 15:04:09 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2016-09-04 15:04:09 +0200
commitc209ed36b6aaaa992df8976789c8ba8112f8e5c5 (patch)
tree750f886c59728842787e58441d39439819050c27 /doc/context/sources/general/manuals/sql
parent1ee48eeafd4e46712a29c91ad704b882f00d765f (diff)
downloadcontext-c209ed36b6aaaa992df8976789c8ba8112f8e5c5.tar.gz
2016-09-04 13:51:00
Diffstat (limited to 'doc/context/sources/general/manuals/sql')
-rw-r--r--doc/context/sources/general/manuals/sql/sql-mkiv.tex88
1 files changed, 88 insertions, 0 deletions
diff --git a/doc/context/sources/general/manuals/sql/sql-mkiv.tex b/doc/context/sources/general/manuals/sql/sql-mkiv.tex
index 1b05c8738..95af57e11 100644
--- a/doc/context/sources/general/manuals/sql/sql-mkiv.tex
+++ b/doc/context/sources/general/manuals/sql/sql-mkiv.tex
@@ -487,6 +487,94 @@ context --extra=sql-tables --help
\stopsection
+\startsection[title=Example]
+
+The distribution has a few examples, for instance a logger. The following code shows
+a bit of this (we assume that the swiglib sqlite module is present):
+
+\startbuffer
+require("util-sql")
+utilities.sql.setmethod("sqlite")
+require("util-sql-loggers")
+
+local loggers = utilities.sql.loggers
+
+local presets = {
+ -- method = "sqlite",
+ database = "loggertest",
+ datatable = "loggers",
+ id = "loggers",
+}
+
+os.remove("loggertest.db") -- start fresh
+
+local db = loggers.createdb(presets)
+
+loggers.save(db, { -- variant 1: data subtable
+ type = "error",
+ action = "process",
+ data = { filename = "test-1", message = "whatever a" }
+} )
+
+loggers.save(db, { -- variant 2: flat table
+ type = "warning",
+ action = "process",
+ filename = "test-2",
+ message = "whatever b"
+} )
+
+
+local result = loggers.collect(db, {
+ start = {
+ day = 1,
+ month = 1,
+ year = 2016,
+ },
+ stop = {
+ day = 31,
+ month = 12,
+ year = 2116,
+ },
+ limit = 1000000,
+ -- type = "error",
+ action = "process"
+})
+
+context.starttabulate { "||||||" }
+for i=1,#result do
+ local r = result[i]
+ context.NC() context(r.time)
+ context.NC() context(r.type)
+ context.NC() context(r.action)
+ if r.data then
+ context.NC() context(r.data.filename)
+ context.NC() context(r.data.message)
+ else
+ context.NC()
+ context.NC()
+ end
+ context.NC() context.NR()
+end
+context.stoptabulate()
+
+-- local result = loggers.cleanup(db, {
+-- before = {
+-- day = 1,
+-- month = 1,
+-- year = 2117,
+-- },
+-- })
+\stopbuffer
+
+\typebuffer
+
+In this example we typeset the (small) table):
+
+\ctxluabuffer
+
+
+\stopsection
+
\startsection[title=Colofon]
\starttabulate[|B|p|]