1 unstable release
| 0.1.0 | Nov 7, 2022 |
|---|
#10 in #query-dsl
23KB
535 lines
DSV Seeker
A small tool to run basic queries on DSV files.
Commands
"select" ("*" | (name ("," name)*))
The select command keeps only the desired columns.
"where" name (("=" value) | ("like" pattern))
The where command filters rows based on string equality or pattern matching of the value in the named column.
"enum" name
The enum command outputs two columns, respectively the number of appearances of a value and the value itself.
This is similar in a way to running uniq -c in Bash.
"sort" "num"? name ("asc" | "desc")
The sort command sorts rows based on the named column.
"trim" ("*" | (name ("," name)*))
The trim command removes heading and trailing whitespace from desired columns' values.
behead
The behead command removes the first line, that usually being the headers.
How to add a new command
Commands are organized in isolated modules as much as possible.
Steps
- Add the grammar rule to the grammar.pest file:
- Create a new rule under the other commands' rules, right above the
commandrule. - Add that rule to the end of the
commandrule.
- Create a new rule under the other commands' rules, right above the
- Add your command to the
Commandenum insrc/ast.rs. - Handle matching from the rule to a new
Command::[your_rule]insrc/ast.rs::build_command. - Create your command's file in
src/operators/and add the new module tosrc/operators/mod.rs. - Look at other commands to figure out how to write yours.
- Add the match case for your rule in
src/ast.rs::Ast::run_on. - Add the command to this README and to the
src/main.rs::Clidoc comment.
Dependencies
~6–8MB
~132K SLoC