Skip to content

04 ‐ How To Use

Michael Dick edited this page Aug 15, 2023 · 3 revisions

All Available db-tool Commands

Overview

command description
create-profile Create a new profile for db-tool
list-profiles List all locally available profiles
grep Grep-like tool to search through databases
list-tables List all tables from a database
-h / --help Show the help overview (Can be used together with other commands e.g. create-profile --help
-V / --version Print version information

Core Syntax

db-tool <COMMAND> <OPTIONS> [VALUES]

Append -h / --help to a command to print out available options!

Commands

create-profile - Create a new connection profile

To create a new connection profile, use the following command:

db-tool create-profile -n [NAME] -h [HOST] - p [PORT] -db [DATABASE_NAME] -u [USERNAME] -pw [PASSWORD] -t [DATABASE_TYPE] -d [DRIVER_PATH] -o [OUTPUT_PATH]

The profile will be saved in the profiles folder. With the -d option you can specify the path to the driver jar file. If you don't specify the path, the tool will only use the predefined drivers (MySQL, PostgreSql and SQLite).

The Database Type can be one of the following:

  • MYSQL
  • SQLITE
  • OTHERS

MySQL and SQLite are tested and should work. The OTHERS type is not tested and may not work.

It is important to correctly handle all possible errors/exceptions. For example, if the user enters a wrong database type, the tool should print an error message and exit. Also, a wrong driver path should be handled correctly. If the config file is invalid, the tool should print an error message and exit.

If the computer is not connected to the internet and the user tries to connect to an external database, the tool should print an error message and exit. In general, the tool should not crash, but print an valuable error message and exit.

list-profiles - List all connection profiles

To list all connection profiles, use the following command:

db-tool list-profiles

list-tables - List all tables in a database

To get a quick overview of a database, you can use the list-tables subcommand of the tool to print out every table in the database:

db-tool list-tables

grep - Search through a database

To search through a database, this tool is offering multiple options. The user can search for a specific table, column or value. A distinction is made between the pattern (like) search and the regex search. The pattern search is used to search for a specific value. The regex search is used to search for a pattern. They both can be combined and used together. When used together the search will be executed like an AND operation.

Pattern search

To search for a specific value, use the following command:

db-tool grep -p [PROFILE_NAME] -tp [TABLE_PATTERN] -cp [COLUMN_PATTERN] -vp [VALUE_PATTERN]

The -tp option is used to specify the table pattern. Therefore, only the tables matching the pattern will be searched for. The -cp option is used to specify the column pattern. Therefore, only the columns matching the pattern will be searched for. The -vp option is used to specify the value pattern. Therefore, only the values matching the pattern will be searched for. You also have the option to use multiple patterns of the same type. This effects the search like an AND operation.

Here is a example that will search trough the table users and admin and print all columns:

db-tool grep -p [PROFILE_NAME] -tp "users" -tp "admin"

Regex search

db-tool is also offering a regex search in addition to the pattern search. To use the regex search, use the following command:

db-tool grep -p [PROFILE_NAME] -tr [TABLE_REGEX] -cr [COLUMN_REGEX]

The -tr option is used to specify the table regex. Therefore, only the tables matching the regex will be searched. The -cr option is used to specify the column regex. Therefore, only the columns matching the regex will be searched.

Here is a example, that will search in the users or admin table and also searches through the colums to only match letters:

db-tool grep -p [PROFILE_NAME] -tr "(users)|(admins)" -cr "[a-zA-Z]+"

Value compares

With value compare, you are able to search through specific numeric columns or all of them in a table. It will simply limit the result based on your compare operation. For example, if you would like to only select users where the id is greater than 10, you can use:

db-tool grep -p [PROFILE_NAME] -tr "(users)|(admins)" -vp "id > 10"

It is also possible to not specify a column. Therefore the tool will search through every column values:

db-tool grep -p [PROFILE_NAME] -tr "(users)|(admins)" -vp "> 10"

Combining pattern, regex and value compare search

Is is possible to combine as many pattern, regex and value compare console parameters as you like.

Limit the search result

Limit the text length

It is possible to limit the text length in the search result. The following command gives an example:

db-tool grep -p [PROFILE_NAME] [...] -lt [TEXT_LENGTH]

The -lt option is used to specify the text length. If the text is longer than the specified length, the text will be cut off and an ellipsis will be added.

Here is a example, that will search in the users table in the name column and only show the first 10 characters of the value:

db-tool grep -p [PROFILE_NAME] -tp "users" -cp "name" -lt 10
Limit the number of rows

It is possible to limit the number of rows in the search result. To do this, use the following command:

db-tool grep -p [PROFILE_NAME] [...] -lr [ROW_COUNT]

The -lr option is used to specify the row count. Therefore, only the specified number of rows will be shown in the search result.

Here is a example, that will search in the users table in the name column and only show the first 10 rows:

db-tool grep -p [PROFILE_NAME] -tp "users" -cp "name" -lr 10