DBgrep is a command-line application that allows you to search through databases using multiple parameters. It's similar to the grep command, but instead of searching through text files, it searches through databases, making it a powerful tool for data analysis and querying.
DBgrep is built using Java. You'll need to have Java 16 or later installed on your system to run the application. You'll also need to have Maven installed if you want to build the application from source.
To install DBgrep, you can download the latest release in our the GitHub repository. Alternatively, you can clone and build the application from source.
To use DBgrep, you'll need to set up a connection to your database. This is either possible using profile.yml
file or by providing the information as arguments. Providing a profile AND
the database properties as arguments at the same time is not possible.
A profile is a configuration file that contains the information needed to connect to a database. You can create a
profile following the syntax below. After creating the profile.yml file you are able to use it via the commandline by
providing the --profile <path/to/profile.yml>
argument and specifying the profile path.
driver: drivers\mariadb-java-client-3.1.0.jar
host: localhost
port: 3306
dbname: dbgrep
username: root
password: example
protocol: jdbc:mariadb
For MongoDB, the syntax is as follows:
host: localhost
port: 27017
dbname: dbgrep
username: root
password: example
protocol: mongodb
A driver is not needed for MongoDB.
Alternatively, you can also set up a database connection by providing the required information as commandline arguments.
When doing so, the --profile
argument is not required.
--dbname=<dbname>
--driver=<driver>
--host=<host>
--password=<password>
--port=<port>
--protocol=<protocol>
--username=<username>
-p, --profile=<profile> connection path/profile
Once you've installed DBgrep, you can use it to search through databases. The basic syntax of the commands is as follows:
-c, --column=<pattern> Search through the column names for the provided pattern.
-c, --column=<column name> <pattern> Search through the values of the specified column name.
-t, --table=<table> Specifies table to be searched.
= (equals)
!= (not equals)
< (less than)
> (greater than)
+ (regex match)
There must not be spaces after operators or the expression must be written in quotation marks
If you get lost you can use dbgrep --help
to get a list of all available commands and options.
dbgrep --help
Search for all table names beginning with a capital "K":
java --jar ./dbgrep.jar -p "path/to/profile.yml" -t "K.*" # for MongoDB
java --jar ./dbgrep.jar -p "path/to/profile.yml" -t "K" # for SQL databases
Search for all column names in containing named something with "price" in all tables beginning with "K":
java --jar ./dbgrep.jar -p "path/to/profile.yml" -t "K.*" -c ".*price.*" # for MongoDB
java --jar ./dbgrep.jar -p "path/to/profile.yml" -t "K" -c "price" # for SQL databases
Search for values of the column "price" in the Table "laptops" which are smaller than 500:
java --jar ./dbgrep.jar -p "path/to/profile.yml" -t "laptops" -c "price" "<500"
Docker and Docker-Compose need to be installed for the following steps. In addition, the repository needs to be cloned.
To start up a MongoDB, a MariaDB and a Postgresql database you can use the provided docker-compose file. Either execute:
docker-compose -f ./docker/docker-compose.yml up
Or use the provided startup script:
./start_db.sh
It is possible to insert some test data in these databases using the provided FillDB.jar
.
Simply execute:
java -jar ./filldb.jar
DBgrep relies on several external libraries, the most important ones are:
- Junit 5
- Picocli
- Jackson
- Apache Commons Collections
- MongoDB Driver
- PostgreSQL Driver
DBgrep is released under the MIT License.