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
inspectcommand and its options.
- Shows the help message for the
--in <TABLE>or--in <TABLE.COLUMN>- Specify one or more tables or columns to inspect. Can be used multiple times.
- Example:
--in usersor--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
inspectwithout 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 inspectbash
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 usersbash
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.namebash
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 pkeysbash
Table: users
┏━━━━━━━━━━━━┳━━━━━━━━━┓
┃ name ┃ columns ┃
┡━━━━━━━━━━━━╇━━━━━━━━━┩
│ users_pkey │ id │
└────────────┴─────────┘Show foreign keys for a table
bash
dbgrep --config config.json inspect --in employees fkeysbash
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 indexesbash
Table: users
┏━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━┓
┃ name ┃ unique ┃ columns ┃
┡━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━┩
│ users_email_key │ True │ ['email'] │
└─────────────────┴────────┴───────────┘