5 <nadpis>Examples</nadpis> |
5 <nadpis>Examples</nadpis> |
6 <perex>Usage examples of Relational pipes tools</perex> |
6 <perex>Usage examples of Relational pipes tools</perex> |
7 <pořadí>40</pořadí> |
7 <pořadí>40</pořadí> |
8 |
8 |
9 <text xmlns="http://www.w3.org/1999/xhtml"> |
9 <text xmlns="http://www.w3.org/1999/xhtml"> |
|
10 |
|
11 |
|
12 <h3>relpipe-in-cli: Hello Wordl!</h3> |
|
13 |
|
14 <p> |
|
15 Let's start with and obligatory Hello World example. |
|
16 </p> |
|
17 |
|
18 <m:pre jazyk="bash"><![CDATA[relpipe-in-cli generate "relation_from_cli" 3 \ |
|
19 "a" "integer" \ |
|
20 "b" "string" \ |
|
21 "c" "boolean" \ |
|
22 "1" "Hello" "true" \ |
|
23 "2" "World!" "false"]]></m:pre> |
|
24 |
|
25 <p> |
|
26 This command generates relational data. |
|
27 In order to see them, we need to convert them to some other format. |
|
28 For now, we will use the "tabular" format and pipe relational data to the <code>relpipe-out-tabular</code>. |
|
29 </p> |
|
30 |
|
31 <m:pre jazyk="bash"><![CDATA[relpipe-in-cli generate "relation_from_cli" 3 \ |
|
32 "a" "integer" \ |
|
33 "b" "string" \ |
|
34 "c" "boolean" \ |
|
35 "1" "Hello" "true" \ |
|
36 "2" "World!" "false" \ |
|
37 | relpipe-out-tabular]]></m:pre> |
|
38 |
|
39 <p>Output:</p> |
|
40 |
|
41 <pre><![CDATA[relation_from_cli: |
|
42 ╭─────────────┬────────────┬─────────────╮ |
|
43 │ a (integer) │ b (string) │ c (boolean) │ |
|
44 ├─────────────┼────────────┼─────────────┤ |
|
45 │ 1 │ Hello │ true │ |
|
46 │ 2 │ World! │ false │ |
|
47 ╰─────────────┴────────────┴─────────────╯ |
|
48 Record count: 2 |
|
49 ]]></pre> |
|
50 |
|
51 <p> |
|
52 The syntax is simple as we see above. We specify the name of the relation, number of attributes, |
|
53 and then their definitions (names and types), |
|
54 followed by the data. |
|
55 </p> |
|
56 |
|
57 <h3>relpipe-in-cli: STDIN</h3> |
|
58 |
|
59 <p> |
|
60 The number of CLI arguments is limited and their are passed at once to the process. |
|
61 So there is option to pass the values from STDIN instead of CLI arguments. |
|
62 Values on STDIN are expected to be separated by the null-byte. |
|
63 We can generate such data e.g. using <code>echo</code> and <code>tr</code> (or using <code>printf</code> or other commands): |
|
64 </p> |
|
65 |
|
66 <m:pre jazyk="bash"><![CDATA[echo -e "1\nHello\ntrue\n2\nWorld\nfalse" \ |
|
67 | tr \\n \\0 \ |
|
68 | relpipe-in-cli generate-from-stdin relation_from_stdin 3 \ |
|
69 a integer \ |
|
70 b string \ |
|
71 c boolean \ |
|
72 | relpipe-out-tabular]]></m:pre> |
|
73 |
|
74 <p> |
|
75 The output is same as above. |
|
76 We can use this approach to convert various formats to relational data. |
|
77 There are lot of data already in the form of null-separated values e.g. the process arguments: |
|
78 </p> |
|
79 |
|
80 <m:pre jazyk="bash"><![CDATA[cat /proc/$(pidof mc)/cmdline \ |
|
81 | relpipe-in-cli generate-from-stdin mc_args 1 a string \ |
|
82 | relpipe-out-tabular |
|
83 ]]></m:pre> |
|
84 |
|
85 <p>If we have <code>mc /etc/ /tmp/</code> running in some other terminal, the output will be:</p> |
|
86 |
|
87 <pre><![CDATA[mc_args: |
|
88 ╭────────────╮ |
|
89 │ a (string) │ |
|
90 ├────────────┤ |
|
91 │ mc │ |
|
92 │ /etc/ │ |
|
93 │ /tmp/ │ |
|
94 ╰────────────╯ |
|
95 Record count: 3]]></pre> |
|
96 |
|
97 <p> |
|
98 Also the <code>find</code> command can produce data separated by the null-byte: |
|
99 </p> |
|
100 |
|
101 <m:pre jazyk="bash"><![CDATA[find /etc/ -name '*ssh*_*' -print0 \ |
|
102 | relpipe-in-cli generate-from-stdin files 1 file_name string \ |
|
103 | relpipe-out-tabular]]></m:pre> |
|
104 |
|
105 <p>Will display something like this:</p> |
|
106 |
|
107 <pre><![CDATA[files: |
|
108 ╭───────────────────────────────────╮ |
|
109 │ file_name (string) │ |
|
110 ├───────────────────────────────────┤ |
|
111 │ /etc/ssh/ssh_host_ecdsa_key │ |
|
112 │ /etc/ssh/sshd_config │ |
|
113 │ /etc/ssh/ssh_host_ed25519_key.pub │ |
|
114 │ /etc/ssh/ssh_host_ecdsa_key.pub │ |
|
115 │ /etc/ssh/ssh_host_rsa_key │ |
|
116 │ /etc/ssh/ssh_config │ |
|
117 │ /etc/ssh/ssh_host_ed25519_key │ |
|
118 │ /etc/ssh/ssh_import_id │ |
|
119 │ /etc/ssh/ssh_host_rsa_key.pub │ |
|
120 ╰───────────────────────────────────╯ |
|
121 Record count: 9]]></pre> |
10 |
122 |
11 |
123 |
12 <h3>relpipe-tr-validator</h3> |
124 <h3>relpipe-tr-validator</h3> |
13 |
125 |
14 <p> |
126 <p> |