--- a/relpipe-data/examples-guile-aggregations.xml Thu Feb 07 16:24:21 2019 +0100
+++ b/relpipe-data/examples-guile-aggregations.xml Thu Feb 07 17:55:05 2019 +0100
@@ -34,7 +34,7 @@
Record count: 1]]></m:pre>
<p>
- In SQL same result can be achieved by:
+ In SQL, the same result can be achieved by:
</p>
<m:pre jazyk="sql"><![CDATA[SELECT
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/relpipe-data/examples-guile-multiple-relations.xml Thu Feb 07 17:55:05 2019 +0100
@@ -0,0 +1,95 @@
+<stránka
+ xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
+ xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
+
+ <nadpis>Processing multiple relations with Guile</nadpis>
+ <perex>filter some relations and others keep unaffected</perex>
+ <m:pořadí-příkladu>01800</m:pořadí-příkladu>
+
+ <text xmlns="http://www.w3.org/1999/xhtml">
+
+ <p>
+ The <code>relpipe-tr-guile</code> is capable to process multiple relations in a single pass.
+ So we can filter some relations and let others flow unaffected through this pipeline step.
+ </p>
+
+ <m:pre jazyk="bash"><![CDATA[# define some sample relational functions:
+r1() { relpipe-in-cli generate seq 1 i integer 1 2 3; } # seq
+r2() { relpipe-in-fstab; } # fstab
+r3() { find /usr/share/sounds/ -print0 | relpipe-in-filesystem; } # filesystem
+
+# put them together in a single stream function:
+sample-data() { r1; r2; r3; }
+
+# let them flow through our Guile transformation:
+sample-data \
+ | relpipe-tr-guile \
+ --relation fstab \
+ --where '(or (string= $type "btrfs") (string-prefix? "/mnt/" $mount_point) )' \
+ --relation filesystem \
+ --where '(and (> $size 8000) (< $size 9000) )' \
+ | relpipe-out-tabular]]></m:pre>
+
+ <p>Such script will generate something like this:</p>
+
+ <m:pre jazyk="text"><![CDATA[seq:
+ ╭─────────────╮
+ │ i (integer) │
+ ├─────────────┤
+ │ 1 │
+ │ 2 │
+ │ 3 │
+ ╰─────────────╯
+Record count: 3
+
+fstab:
+ ╭─────────────────┬──────────────────────────────────────┬──────────────────────┬───────────────┬───────────────────────────────────────┬────────────────┬────────────────╮
+ │ scheme (string) │ device (string) │ mount_point (string) │ type (string) │ options (string) │ dump (integer) │ pass (integer) │
+ ├─────────────────┼──────────────────────────────────────┼──────────────────────┼───────────────┼───────────────────────────────────────┼────────────────┼────────────────┤
+ │ │ /dev/sde │ /mnt/data │ ext4 │ relatime,user_xattr,errors=remount-ro │ 0 │ 2 │
+ │ UUID │ a2b5f230-a795-4f6f-a39b-9b57686c86d5 │ /home │ btrfs │ relatime │ 0 │ 2 │
+ │ │ /dev/mapper/sdf_crypt │ /mnt/private │ xfs │ relatime │ 0 │ 2 │
+ ╰─────────────────┴──────────────────────────────────────┴──────────────────────┴───────────────┴───────────────────────────────────────┴────────────────┴────────────────╯
+Record count: 3
+
+filesystem:
+ ╭───────────────────────────────────────────────────────────────────────────┬───────────────┬────────────────┬────────────────┬────────────────╮
+ │ path (string) │ type (string) │ size (integer) │ owner (string) │ group (string) │
+ ├───────────────────────────────────────────────────────────────────────────┼───────────────┼────────────────┼────────────────┼────────────────┤
+ │ /usr/share/sounds/Oxygen-Window-All-Desktops-Not.ogg │ f │ 8363 │ root │ root │
+ │ /usr/share/sounds/KDE-Window-All-Desktops-Not.ogg │ f │ 8363 │ root │ root │
+ │ /usr/share/sounds/Oxygen-Window-Close.ogg │ f │ 8865 │ root │ root │
+ │ /usr/share/sounds/KDE-Window-Close.ogg │ f │ 8865 │ root │ root │
+ │ /usr/share/sounds/KDE-Window-All-Desktops.ogg │ f │ 8712 │ root │ root │
+ │ /usr/share/sounds/Oxygen-Window-All-Desktops.ogg │ f │ 8712 │ root │ root │
+ │ /usr/share/sounds/freedesktop/stereo/power-plug.oga │ l │ 8748 │ root │ root │
+ │ /usr/share/sounds/freedesktop/stereo/bell.oga │ f │ 8495 │ root │ root │
+ │ /usr/share/sounds/freedesktop/stereo/network-connectivity-established.oga │ l │ 8748 │ root │ root │
+ │ /usr/share/sounds/freedesktop/stereo/device-removed.oga │ f │ 8500 │ root │ root │
+ │ /usr/share/sounds/freedesktop/stereo/device-added.oga │ f │ 8748 │ root │ root │
+ │ /usr/share/sounds/freedesktop/stereo/power-unplug.oga │ l │ 8500 │ root │ root │
+ │ /usr/share/sounds/freedesktop/stereo/network-connectivity-lost.oga │ l │ 8500 │ root │ root │
+ ╰───────────────────────────────────────────────────────────────────────────┴───────────────┴────────────────┴────────────────┴────────────────╯
+Record count: 13]]></m:pre>
+
+
+ <p>
+ In Guile, we have filtered the <code>fstab</code> and <code>filesystem</code> relations
+ while the <code>seq</code> relation was kept intact.
+ </p>
+
+ <p>
+ The <code>--relation</code> option accepts a regular expression.
+ So it is possible to process more than one relation with it (having all needed attributes in each, of course).
+ If more <code>--relation</code> options (e.g. <code>'f.*'</code> and <code>fstab</code>) matches the same relation in the stream, only the first wins and transforms that relation.
+ </p>
+
+ <p>
+ If we define some variables in the Guile context, they will stay there – so we can pass data across relations.
+ Thus we can do even JOIN, if we really want.
+ </p>
+
+
+ </text>
+
+</stránka>