SQL in WeeWiki

SQL in WeeWiki

This page aims to outline some small SQL tricks in WeeWiki.

WeeWiki bundles a version of the SQLite Janet bindings, so this allows WeeWiki to query sqlite databases (include itself) and dynamically produce content.

Accessing WeeWiki Variables

WeeWiki can access itself (the currently opened database) with the function ww-db. This can then be used with any of the SQLite3 janet functions.

My WeeWiki has a special variable called "@life". The function below will query this page, and print the meaning of life (displayed below):

(do
  (def db (ww-db))
  (def val
    (sqlite3/eval
     db
     "SELECT value FROM wiki where key==\"@life\""))
  (print "The meaning of life is: ")
  (print (get (get val 0) "value")))


The meaning of life is: 42

Parsing Other Pages

Along the same line, the following code will use org instead of print to parse org code found in the ars brevis page:

(do
  (def db (ww-db))
  (def val
    (sqlite3/eval
     db
     "SELECT value FROM wiki where key==\"ars_brevis\""))
  (org (get (get val 0) "value")))

Ars Brevis

A Grook by By Piet Hein

There is

one art,

no more,

no less,

to do

all things

with art-

lessness.

Iterating over values

One can also iterate over values. For instance, this will print the first 25 linked pages in wikilinks in alphabetical order:

(do
  (def db (ww-db))
  (def values
    (sqlite3/eval
     db
     (string
      "SELECT filename FROM wikilinks "
      "ORDER BY filename "
      "COLLATE NOCASE LIMIT 25;")))

  (each file values
    (org
     (string (get file "filename") "\n\n"))))

antilp.org

ars_brevis.org

breathing_cards.org

btprnt.org

cfloop.org

convergence.org

dither.org

equipment.org

event_graph.org

gpd2.org

hclock.org

index.org

literate_programming.org

lp_recipe.org

maille.org

MIDI_sucks.org

monolinux.org

monolith.org

norns.org

sample_curation.org

sixtycolumnrule.org

thoughtful_programming.org

tiziku.org

twtxt.org

verbsmetafont.org