Skip to content

Inspect Command ​

The inspect command allows you to examine the structure of your database, including tables, columns, primary keys, foreign keys, and indexes.

Options ​

  • --help

    • Shows the help message for the inspect command and its options.
  • --in <TABLE> or --in <TABLE.COLUMN>

    • Specify one or more tables or columns to inspect. Can be used multiple times.
    • Example: --in users or --in users.name
  • inspect pkeys

    • Show primary keys for the specified table(s).
  • inspect fkeys

    • Show foreign keys for the specified table(s).
  • inspect indexes

    • Show indexes for the specified table(s).

Notes ​

  • If you run inspect without any options, it prints the full schema (all tables and columns).

Usage ​

dbgrep [--config <file>] [--format <table|json|yaml>] [--output <file>] inspect [--in <table|table.column>] [pkeys|fkeys|indexes]

Examples ​

Show the full schema (all tables and columns) ​

bash
dbgrep --config config.json inspect
bash
                                          Table: users                                           
┏━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ name  ┃ type         ┃ nullable ┃ default                           ┃ autoincrement ┃ comment ┃
┡━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━┩
│ id    │ INTEGER      │ -        │ nextval('users_id_seq'::regclass) │ True          │ -       │
│ name  │ VARCHAR(50)  │ True     │ -                                 │ -             │ -       │
│ email │ VARCHAR(100) │ True     │ -                                 │ -             │ -       │
└───────┴──────────────┴──────────┴───────────────────────────────────┴───────────────┴─────────┘
                                               Table: employees
┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ name          ┃ type           ┃ nullable ┃ default                               ┃ autoincrement ┃ comment ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━┩
│ id            │ INTEGER        │ -        │ nextval('employees_id_seq'::regclass) │ True          │ -       │
│ user_id       │ INTEGER        │ True     │ -                                     │ -             │ -       │
│ department_id │ INTEGER        │ True     │ -                                     │ -             │ -       │
│ position      │ VARCHAR(100)   │ True     │ -                                     │ -             │ -       │
│ salary        │ NUMERIC(10, 2) │ True     │ -                                     │ -             │ -       │
│ hire_date     │ DATE           │ True     │ -                                     │ -             │ -       │
│ active        │ BOOLEAN        │ True     │ true                                  │ -             │ -       │
└───────────────┴────────────────┴──────────┴───────────────────────────────────────┴───────────────┴─────────┘

Show columns for a specific table ​

bash
dbgrep --config config.json inspect --in users
bash
                                          Table: users                                           
┏━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ name  ┃ type         ┃ nullable ┃ default                           ┃ autoincrement ┃ comment ┃
┡━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━┩
│ id    │ INTEGER      │ -        │ nextval('users_id_seq'::regclass) │ True          │ -       │
│ name  │ VARCHAR(50)  │ True     │ -                                 │ -             │ -       │
│ email │ VARCHAR(100) │ True     │ -                                 │ -             │ -       │
└───────┴──────────────┴──────────┴───────────────────────────────────┴───────────────┴─────────┘

Show a specific column ​

bash
dbgrep --config config.json inspect --in users.name
bash
                            Table: users                             
┏━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ name ┃ type        ┃ nullable ┃ default ┃ autoincrement ┃ comment ┃
┡━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━┩
│ name │ VARCHAR(50) │ True     │ -       │ -             │ -       │
└──────┴─────────────┴──────────┴─────────┴───────────────┴─────────┘

Show primary keys for a table ​

bash
dbgrep --config config.json inspect --in users pkeys
bash
      Table: users      
┏━━━━━━━━━━━━┳━━━━━━━━━┓
┃ name       ┃ columns ┃
┡━━━━━━━━━━━━╇━━━━━━━━━┩
│ users_pkey │ id      │
└────────────┴─────────┘

Show foreign keys for a table ​

bash
dbgrep --config config.json inspect --in employees fkeys
bash
                Table: employees                
┏━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ column            ┃ references  ┃ ref_column ┃
┡━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ ['department_id'] │ departments │ ['id']     │
│ ['user_id']       │ users       │ ['id']     │
└───────────────────┴─────────────┴────────────┘

Show indexes for a table ​

bash
dbgrep --config config.json inspect --in users indexes
bash
              Table: users              
┏━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━┓
┃ name            ┃ unique ┃ columns   ┃
┡━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━┩
│ users_email_key │ True   │ ['email'] │
└─────────────────┴────────┴───────────┘