Usage
dbgrep [GLOBAL OPTIONS] COMMAND [COMMAND OPTIONS]The dbgrep CLI follows the structure:
- Global options must be provided before the actual command.
- Commands perform the actions
inspectandsearch. - Command options are passed after the command and are specific to that command.
Global Options
These options are required or available for all commands:
--config <PATH>- Path to a JSON configuration file containing the database connection.
- Cannot be used together with
--db-url.
--db-url <TEXT>- Directly specify the database connection URL as a string.
- Cannot be used together with
--config.
--format <table|json|yaml>- Output format. Default is
table. - Can also be configured in the config file under
formatter.format.
- Output format. Default is
--theme <abap|algol|algol_nu|arduino|autumn|bw|borland|coffee|colorful|default|dracula|emacs|friendly_grayscale|friendly|fruity|github-dark|gruvbox-dark|gruvbox-light|igor|inkpot|lightbulb|lilypond|lovelace|manni|material|monokai|murphy|native|nord-darker|nord|one-dark|paraiso-dark|paraiso-light|pastie|perldoc|rainbow_dash|rrt|sas|solarized-dark|solarized-light|staroffice|stata-dark|stata-light|tango|trac|vim|vs|xcode|zenburn>- Set the output theme for the
jsonandyamlformats. - A demo of all themes can be found here
- Can also be configured in the config file under
formatter.theme.
- Set the output theme for the
--paging/--no-paging- Enable or disable paging for the
tableoutput format. - When enabled, the output will be paginated.
- Navigation keys are:
nfor next pagepfor previous pagejto jump to a specific page, which is promptedqto quit the pager
- Can also be configured in the config file under
formatter.paging.
- Enable or disable paging for the
--output <FILE>- Output the result to a file.
Database Connection
To connect to your database, dbgrep requires exactly one of two connection options to be specified before executing any command.
You can either provide a path to a configuration file or pass the database URL directly. These two options are mutually exclusive and cannot be used together.
The first option to do this is by using the command:
--config PATHPATH: Path to the json configuration file. The file must contain a key named
db_urlwith a valid database URL:json{ "db_url": "postgresql://user:pass@host/db" }Complete configuration file example with all available options:
json{ "db_url": "postgresql://user:pass@host/db", "formatter": { "format": "table", "paging": false, "theme": "monokai" } }The second way to tell
dbgrephow to connet to the database, is by using the command:--db-url TEXTTEXT: Directly specify the database connection URL. This should be a full database connection string such as:
`postgresql://user:password@host:port/database`
Example:
dbgrep --config config.json inspect COMMAND [COMMAND OPTIONS]
# or
dbgrep --db-url "postgresql://user:pass@host/db" COMMAND [COMMAND OPTIONS]Format option
Set the output format for all commands that return structured results.
--format <table|json|yaml>
Output as TABLE
dbgrep --config config.json --format table search --in users --equal "Beta"┏━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ id ┃ name ┃ email ┃
┡━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ 2 │ Beta │ beta@example.com │
└────┴─────────┴─────────────────────┘Output as JSON
dbgrep --config config.json --format json search --in users --equal "Beta"{
"users": [
{
"id": 2,
"name": "Beta",
"email": "beta@example.com"
}
]
}Output as YAML
dbgrep --config config.json --format yaml search --in users --equal "Beta"users:
- id: 2
name: Beta
email: beta@example.comOutput option
Use these option to write the command output directly to a file.
--output FILEPATH
Example
dbgrep --config config.json --format json --output users.json inspect --in users