10 |
10 |
11 <p> |
11 <p> |
12 Let's start with an obligatory Hello World example. |
12 Let's start with an obligatory Hello World example. |
13 </p> |
13 </p> |
14 |
14 |
15 <m:pre jazyk="bash"><![CDATA[relpipe-in-cli generate "relation_from_cli" 3 \ |
15 <m:pre jazyk="bash"><![CDATA[relpipe-in-cli \ |
16 "a" "integer" \ |
16 --relation "relation_from_cli" \ |
17 "b" "string" \ |
17 --attribute "a" "integer" \ |
18 "c" "boolean" \ |
18 --attribute "b" "string" \ |
19 "1" "Hello" "true" \ |
19 --attribute "c" "boolean" \ |
20 "2" "World!" "false"]]></m:pre> |
20 --record "1" "Hello" "true" \ |
|
21 --record "2" "World!" "false"]]></m:pre> |
21 |
22 |
22 <p> |
23 <p> |
23 This command generates relational data. |
24 This command generates relational data. |
24 In order to see them, we need to convert them to some other format. |
25 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 For now, we will use the „tabular“ format and pipe relational data to the <code>relpipe-out-tabular</code>. |
26 </p> |
27 </p> |
27 |
28 |
28 <m:pre jazyk="bash"><![CDATA[relpipe-in-cli generate "relation_from_cli" 3 \ |
29 <m:pre jazyk="bash"><![CDATA[relpipe-in-cli \ |
29 "a" "integer" \ |
30 --relation "relation_from_cli" \ |
30 "b" "string" \ |
31 --attribute "a" "integer" \ |
31 "c" "boolean" \ |
32 --attribute "b" "string" \ |
32 "1" "Hello" "true" \ |
33 --attribute "c" "boolean" \ |
33 "2" "World!" "false" \ |
34 --record "1" "Hello" "true" \ |
|
35 --record "2" "World!" "false" \ |
34 | relpipe-out-tabular]]></m:pre> |
36 | relpipe-out-tabular]]></m:pre> |
35 |
37 |
36 <p>Output:</p> |
38 <p>Output:</p> |
37 |
39 |
38 <pre><![CDATA[relation_from_cli: |
40 <pre><![CDATA[relation_from_cli: |
44 ╰─────────────┴────────────┴─────────────╯ |
46 ╰─────────────┴────────────┴─────────────╯ |
45 Record count: 2 |
47 Record count: 2 |
46 ]]></pre> |
48 ]]></pre> |
47 |
49 |
48 <p> |
50 <p> |
49 The syntax is simple as we see above. We specify the name of the relation, number of attributes, |
51 The syntax is simple as we see above. We specify the name of the relation |
50 and then their definitions (names and types), |
52 and the names and types of attributes |
51 followed by the data. |
53 followed by the data. |
52 </p> |
54 </p> |
53 |
55 |
54 <p> |
56 <p> |
55 A single stream may contain multiple relations: |
57 A single stream may contain multiple relations: |
56 </p> |
58 </p> |
57 |
59 |
58 <m:pre jazyk="bash"><![CDATA[(relpipe-in-cli generate a 1 x string hello; \ |
60 <m:pre jazyk="bash"><![CDATA[(relpipe-in-cli --relation "a" --attribute "x" string --record "hello"; \ |
59 relpipe-in-cli generate b 1 y string world) \ |
61 relpipe-in-cli --relation "b" --attribute "y" string --record "world") \ |
60 | relpipe-out-tabular]]></m:pre> |
62 | relpipe-out-tabular]]></m:pre> |
61 |
63 |
62 <p> |
64 <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: |
65 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> |
66 </p> |
75 │ y (string) │ |
77 │ y (string) │ |
76 ├────────────┤ |
78 ├────────────┤ |
77 │ world │ |
79 │ world │ |
78 ╰────────────╯ |
80 ╰────────────╯ |
79 Record count: 1]]></pre> |
81 Record count: 1]]></pre> |
|
82 |
|
83 <p> |
|
84 In the example above, we call <code>relpipe-in-cli</code> twice and let the shell combine their outputs. |
|
85 This approach is useful when we want to combine relational data from various sources: different <code>relpipe-in-*</code> tools, files etc. |
|
86 But when we work with <code>relpipe-in-cli</code> only, we can ask it to create several relations during one run: |
|
87 </p> |
|
88 |
|
89 <m:pre jazyk="bash"><![CDATA[relpipe-in-cli \ |
|
90 --relation "a" --attribute "x" string --record "hello" \ |
|
91 --relation "b" --attribute "y" string --record "world" \ |
|
92 | relpipe-out-tabular]]></m:pre> |
|
93 |
|
94 <p> |
|
95 The result will be the same. |
|
96 We can also use the <code>--records</code> option instead of the <code>--record</code> option – then the rest of the CLI arguments is treated as data of given relation. |
|
97 Obviously this option can be used only once for the last relation. |
|
98 </p> |
|
99 |
|
100 <m:pre jazyk="bash"><![CDATA[relpipe-in-cli \ |
|
101 --relation "relation_from_cli" \ |
|
102 --attribute "a" "integer" \ |
|
103 --attribute "b" "string" \ |
|
104 --attribute "c" "boolean" \ |
|
105 --records \ |
|
106 "1" "Hello" "true" \ |
|
107 "2" "World!" "false" \ |
|
108 | relpipe-out-tabular]]></m:pre> |
|
109 |
|
110 <p> |
|
111 It will generate the same <code>relation_from_cli</code> table as above. |
|
112 If we have more data (especially from external sources), we can use the <code>--records-on-stdin</code> option and pass them through the <m:a href="examples-cli-stdin">STDIN</m:a>. |
|
113 </p> |
80 |
114 |
81 </text> |
115 </text> |
82 |
116 |
83 </stránka> |
117 </stránka> |