relpipe-data/examples-guile-multiple-relations.xml
author František Kučera <franta-hg@frantovo.cz>
Sat, 06 Jun 2020 13:22:57 +0200
branchv_0
changeset 300 b9bd0f06b4a1
parent 249 ce8a4be95632
child 316 d7ae02390fac
permissions -rw-r--r--
MySQL seems to works well even with libmyodbc5a.so not only libmyodbc5w.so ODBC driver
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
249
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
<stránka
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
	xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
	
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
	<nadpis>Processing multiple relations with Guile</nadpis>
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
	<perex>filter some relations and others keep unaffected</perex>
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
	<m:pořadí-příkladu>01800</m:pořadí-příkladu>
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
	<text xmlns="http://www.w3.org/1999/xhtml">
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
		
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
		<p>
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
			The <code>relpipe-tr-guile</code> is capable to process multiple relations in a single pass.
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
			So we can filter some relations and let others flow unaffected through this pipeline step.
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
		</p>
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
		<m:pre jazyk="bash"><![CDATA[# define some sample relational functions:
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
r1() { relpipe-in-cli generate seq 1 i integer 1 2 3; }             # seq
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
r2() { relpipe-in-fstab; }                                          # fstab
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
r3() { find /usr/share/sounds/ -print0 | relpipe-in-filesystem; }   # filesystem
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
# put them together in a single stream function:
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
sample-data() { r1; r2; r3; }
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
# let them flow through our Guile transformation:
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
sample-data \
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
	| relpipe-tr-guile \
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
		--relation fstab \
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
			--where '(or (string= $type "btrfs") (string-prefix? "/mnt/" $mount_point) )' \
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
		--relation filesystem \
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
			--where '(and (> $size 8000) (< $size 9000) )' \
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
	| relpipe-out-tabular]]></m:pre>
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
	
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
		<p>Such script will generate something like this:</p>
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
		
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
		<m:pre jazyk="text"><![CDATA[seq:
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
 ╭─────────────╮
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
 │ i (integer) │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
 ├─────────────┤
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
 │           1 │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
 │           2 │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
 │           3 │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
 ╰─────────────╯
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
Record count: 3
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
fstab:
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
 ╭─────────────────┬──────────────────────────────────────┬──────────────────────┬───────────────┬───────────────────────────────────────┬────────────────┬────────────────╮
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
 │ scheme (string) │ device                      (string) │ mount_point (string) │ type (string) │ options                      (string) │ dump (integer) │ pass (integer) │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
 ├─────────────────┼──────────────────────────────────────┼──────────────────────┼───────────────┼───────────────────────────────────────┼────────────────┼────────────────┤
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
 │                 │ /dev/sde                             │ /mnt/data            │ ext4          │ relatime,user_xattr,errors=remount-ro │              0 │              2 │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
 │ UUID            │ a2b5f230-a795-4f6f-a39b-9b57686c86d5 │ /home                │ btrfs         │ relatime                              │              0 │              2 │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
 │                 │ /dev/mapper/sdf_crypt                │ /mnt/private         │ xfs           │ relatime                              │              0 │              2 │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
 ╰─────────────────┴──────────────────────────────────────┴──────────────────────┴───────────────┴───────────────────────────────────────┴────────────────┴────────────────╯
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
Record count: 3
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
filesystem:
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
 ╭───────────────────────────────────────────────────────────────────────────┬───────────────┬────────────────┬────────────────┬────────────────╮
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
 │ path                                                             (string) │ type (string) │ size (integer) │ owner (string) │ group (string) │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
 ├───────────────────────────────────────────────────────────────────────────┼───────────────┼────────────────┼────────────────┼────────────────┤
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
 │ /usr/share/sounds/Oxygen-Window-All-Desktops-Not.ogg                      │ f             │           8363 │ root           │ root           │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
 │ /usr/share/sounds/KDE-Window-All-Desktops-Not.ogg                         │ f             │           8363 │ root           │ root           │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
 │ /usr/share/sounds/Oxygen-Window-Close.ogg                                 │ f             │           8865 │ root           │ root           │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
 │ /usr/share/sounds/KDE-Window-Close.ogg                                    │ f             │           8865 │ root           │ root           │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
 │ /usr/share/sounds/KDE-Window-All-Desktops.ogg                             │ f             │           8712 │ root           │ root           │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
 │ /usr/share/sounds/Oxygen-Window-All-Desktops.ogg                          │ f             │           8712 │ root           │ root           │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
 │ /usr/share/sounds/freedesktop/stereo/power-plug.oga                       │ l             │           8748 │ root           │ root           │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
 │ /usr/share/sounds/freedesktop/stereo/bell.oga                             │ f             │           8495 │ root           │ root           │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
 │ /usr/share/sounds/freedesktop/stereo/network-connectivity-established.oga │ l             │           8748 │ root           │ root           │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
 │ /usr/share/sounds/freedesktop/stereo/device-removed.oga                   │ f             │           8500 │ root           │ root           │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
 │ /usr/share/sounds/freedesktop/stereo/device-added.oga                     │ f             │           8748 │ root           │ root           │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
 │ /usr/share/sounds/freedesktop/stereo/power-unplug.oga                     │ l             │           8500 │ root           │ root           │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
 │ /usr/share/sounds/freedesktop/stereo/network-connectivity-lost.oga        │ l             │           8500 │ root           │ root           │
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
 ╰───────────────────────────────────────────────────────────────────────────┴───────────────┴────────────────┴────────────────┴────────────────╯
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
Record count: 13]]></m:pre>
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
		<p>
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
			In Guile, we have filtered the <code>fstab</code> and <code>filesystem</code> relations
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    78
			while the <code>seq</code> relation was kept intact.
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    79
		</p>
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    80
		
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
		<p>
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    82
			The <code>--relation</code> option accepts a regular expression.
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    83
			So it is possible to process more than one relation with it (having all needed attributes in each, of course). 
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    84
			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.
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
		</p>
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
		
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
		<p>
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
			If we define some variables in the Guile context, they will stay there – so we can pass data across relations.
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
			Thus we can do even JOIN, if we really want.
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    90
		</p>
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    91
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    92
		
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    93
	</text>
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    94
ce8a4be95632 examples: Processing multiple relations with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    95
</stránka>