Extending UNIX grep to databases
The grep command among with its myriad of options allows searching text files for the occurrence of strings or patterns. This can be extended both to RDBMS and non-SQL databases like Mongodb.
The database query problem however is more complex than simply query lines of text files. A practically useful CLI must address:
-
Connection profile handling
-
Search level specification:
-
Whole database
-
Table(s)
-
Table column(s)
-
Recordsets
-
-
Output formatting, limiting/filtering and paging
Command | File ~/.dbgrep/Profiles/postgresTest.cfg |
---|---|
dbgrep --profile postgresTest ... |
|
dbgrep ... --equal 237 ❶ dbgrep ... --greater 4.43 ❷ dbgrep ... --like 'Smit%' ❸ dbgrep ... --like 'Smit%' --and --greater 4 ❹ dbgrep ... --range [-3:17] ❺
Search for integer values equal to 237. Return either of:
|
|
Search for numeric values being greater than 4.43. |
|
Texts starting with |
|
Conjunction: Records containing text starting with
|
|
Search for integer values between and including -3 and 17. |
A tool might be implemented either as a single command or as a terminal based application keeping state information.