Skip to content

Usage ​

bash
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 inspect and search.
  • 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.
  • --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 json and yaml formats.
    • A demo of all themes can be found here
    • Can also be configured in the config file under formatter.theme.
  • --paging/--no-paging

    • Enable or disable paging for the table output format.
    • When enabled, the output will be paginated.
    • Navigation keys are:
      • n for next page
      • p for previous page
      • j to jump to a specific page, which is prompted
      • q to quit the pager
    • Can also be configured in the config file under formatter.paging.
  • --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 PATH

    PATH: Path to the json configuration file. The file must contain a key named db_url with 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 dbgrep how to connet to the database, is by using the command:

    --db-url TEXT

    TEXT: Directly specify the database connection URL. This should be a full database connection string such as:

    `postgresql://user:password@host:port/database`

Example:

bash
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

bash
dbgrep --config config.json --format table search --in users --equal "Beta"
bash
┏━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ id ┃ name    ┃ email               ┃
┡━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ 2  │ Beta    │ beta@example.com    │
└────┴─────────┴─────────────────────┘

Output as JSON

bash
dbgrep --config config.json --format json search --in users --equal "Beta"
bash
{
  "users": [
    {                                                                                                                                                                                                                               
      "id": 2,
      "name": "Beta",
      "email": "beta@example.com"
    }                                                                                                                                                                                                                               
  ]                                                                                                                                                                                                                                 
}

Output as YAML

bash
dbgrep --config config.json --format yaml search --in users --equal "Beta"
bash
users:
- id: 2
  name: Beta
  email: beta@example.com

Output option ​

Use these option to write the command output directly to a file.

--output FILEPATH

Example

bash
dbgrep --config config.json --format json --output users.json inspect --in users