|
1 <stránka |
|
2 xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana" |
|
3 xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"> |
|
4 |
|
5 <nadpis>Hello Wordl!</nadpis> |
|
6 <perex>generating relational data from CLI arguments</perex> |
|
7 <m:pořadí-příkladu>00100</m:pořadí-příkladu> |
|
8 |
|
9 <text xmlns="http://www.w3.org/1999/xhtml"> |
|
10 |
|
11 <p> |
|
12 Let's start with an obligatory Hello World example. |
|
13 </p> |
|
14 |
|
15 <m:pre jazyk="bash"><![CDATA[relpipe-in-cli generate "relation_from_cli" 3 \ |
|
16 "a" "integer" \ |
|
17 "b" "string" \ |
|
18 "c" "boolean" \ |
|
19 "1" "Hello" "true" \ |
|
20 "2" "World!" "false"]]></m:pre> |
|
21 |
|
22 <p> |
|
23 This command generates relational data. |
|
24 In order to see them, we need to convert them to some other format. |
|
25 For now, we will use the "tabular" format and pipe relational data to the <code>relpipe-out-tabular</code>. |
|
26 </p> |
|
27 |
|
28 <m:pre jazyk="bash"><![CDATA[relpipe-in-cli generate "relation_from_cli" 3 \ |
|
29 "a" "integer" \ |
|
30 "b" "string" \ |
|
31 "c" "boolean" \ |
|
32 "1" "Hello" "true" \ |
|
33 "2" "World!" "false" \ |
|
34 | relpipe-out-tabular]]></m:pre> |
|
35 |
|
36 <p>Output:</p> |
|
37 |
|
38 <pre><![CDATA[relation_from_cli: |
|
39 ╭─────────────┬────────────┬─────────────╮ |
|
40 │ a (integer) │ b (string) │ c (boolean) │ |
|
41 ├─────────────┼────────────┼─────────────┤ |
|
42 │ 1 │ Hello │ true │ |
|
43 │ 2 │ World! │ false │ |
|
44 ╰─────────────┴────────────┴─────────────╯ |
|
45 Record count: 2 |
|
46 ]]></pre> |
|
47 |
|
48 <p> |
|
49 The syntax is simple as we see above. We specify the name of the relation, number of attributes, |
|
50 and then their definitions (names and types), |
|
51 followed by the data. |
|
52 </p> |
|
53 |
|
54 <p> |
|
55 A single stream may contain multiple relations: |
|
56 </p> |
|
57 |
|
58 <m:pre jazyk="bash"><![CDATA[(relpipe-in-cli generate a 1 x string hello; \ |
|
59 relpipe-in-cli generate b 1 y string world) \ |
|
60 | relpipe-out-tabular]]></m:pre> |
|
61 |
|
62 <p> |
|
63 Thus we can combine various commands or files and pass the result to a single relational output filter (<code>relpipe-out-tabular</code> in this case) and get: |
|
64 </p> |
|
65 |
|
66 <pre><![CDATA[a: |
|
67 ╭────────────╮ |
|
68 │ x (string) │ |
|
69 ├────────────┤ |
|
70 │ hello │ |
|
71 ╰────────────╯ |
|
72 Record count: 1 |
|
73 b: |
|
74 ╭────────────╮ |
|
75 │ y (string) │ |
|
76 ├────────────┤ |
|
77 │ world │ |
|
78 ╰────────────╯ |
|
79 Record count: 1]]></pre> |
|
80 |
|
81 </text> |
|
82 |
|
83 </stránka> |