Let's start with an obligatory Hello World example.
relpipe-in-cli \
--relation "relation_from_cli" \
--attribute "a" "integer" \
--attribute "b" "string" \
--attribute "c" "boolean" \
--record "1" "Hello" "true" \
--record "2" "World!" "false"
This command generates relational data.
In order to see them, we need to convert them to some other format.
For now, we will use the „tabular“ format and pipe relational data to the relpipe-out-tabular
.
relpipe-in-cli \
--relation "relation_from_cli" \
--attribute "a" "integer" \
--attribute "b" "string" \
--attribute "c" "boolean" \
--record "1" "Hello" "true" \
--record "2" "World!" "false" \
| relpipe-out-tabular
Output:
relation_from_cli: ╭─────────────┬────────────┬─────────────╮ │ a (integer) │ b (string) │ c (boolean) │ ├─────────────┼────────────┼─────────────┤ │ 1 │ Hello │ true │ │ 2 │ World! │ false │ ╰─────────────┴────────────┴─────────────╯ Record count: 2
The syntax is simple as we see above. We specify the name of the relation and the names and types of attributes followed by the data.
A single stream may contain multiple relations:
(relpipe-in-cli --relation "a" --attribute "x" string --record "hello"; \
relpipe-in-cli --relation "b" --attribute "y" string --record "world") \
| relpipe-out-tabular
Thus we can combine various commands or files and pass the result to a single relational output filter (relpipe-out-tabular
in this case) and get:
a: ╭────────────╮ │ x (string) │ ├────────────┤ │ hello │ ╰────────────╯ Record count: 1 b: ╭────────────╮ │ y (string) │ ├────────────┤ │ world │ ╰────────────╯ Record count: 1
In the example above, we call relpipe-in-cli
twice and let the shell combine their outputs.
This approach is useful when we want to combine relational data from various sources: different relpipe-in-*
tools, files etc.
But when we work with relpipe-in-cli
only, we can ask it to create several relations during one run:
relpipe-in-cli \
--relation "a" --attribute "x" string --record "hello" \
--relation "b" --attribute "y" string --record "world" \
| relpipe-out-tabular
The result will be the same.
We can also use the --records
option instead of the --record
option – then the rest of the CLI arguments is treated as data of given relation.
Obviously this option can be used only once for the last relation.
relpipe-in-cli \
--relation "relation_from_cli" \
--attribute "a" "integer" \
--attribute "b" "string" \
--attribute "c" "boolean" \
--records \
"1" "Hello" "true" \
"2" "World!" "false" \
| relpipe-out-tabular
It will generate the same relation_from_cli
table as above.
If we have more data (especially from external sources), we can use the --records-on-stdin
option and pass them through the STDIN.
Relational pipes, open standard and free software © 2018-2022 GlobalCode