Search Command
The search command allows you to search for specific values within your database tables. It provides various options for different types of searches, from exact matches to pattern matching and numerical comparisons.
Options
The search command provides several options to control how you search for data:
--help- Shows the help message specifically for the
searchcommand and its options
- Shows the help message specifically for the
--in TEXT- Specifies where to search using table or table.column notation (e.g.,
users.name) - Required to specify the target of your search
- Specifies where to search using table or table.column notation (e.g.,
--equal TEXT- Searches for values that exactly match the given text
- Case-sensitive exact matching
--like TEXT- Searches for values using pattern matching
- Use
%as a wildcard character - Example:
%john%will match "john", "johnny", "johnson", etc.
--greater TEXT- Finds all values greater than the given number
- Use with numerical columns
--less TEXT- Finds all values less than the given number
- Use with numerical columns
Notes
- You must specify at least one of:
--equal,--like,--greater, or--less. - Multiple comparison options can be combined and are logically ANDed by default.
For example, using--like "%john%" --greater 50000will return results that match both conditions. - The
--inoption supports specifying either full tables or individual columns.
Usage
dbgrep [--config <file>] [--format <table|json|yaml>] [--output <file>] search [--in <table|table.column>] [--equal TEXT] [--like TEXT] [--greater TEXT] [--less TEXT]Examples
Match in all tables
bash
dbgrep --config config.json search search --like "%Marketing%"bash
Table: employees
┏━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━┓
┃ id ┃ user_id ┃ department_id ┃ position ┃ salary ┃ hire_date ┃ active ┃
┡━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━┩
│ 2 │ 2 │ 2 │ Marketing Specialist │ 65000.0 │ 2022-01-10 │ True │
└────┴─────────┴───────────────┴──────────────────────┴─────────┴────────────┴────────┘
Table: departments
┏━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ id ┃ name ┃ location ┃
┡━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ 2 │ Marketing │ Building B │
└────┴───────────┴────────────┘Exact match in a specific table
bash
dbgrep --config config.json search --in users --equal "Beta"bash
Table: users
┏━━━━┳━━━━━━┳━━━━━━━━━━━━━━━━━━┓
┃ id ┃ name ┃ email ┃
┡━━━━╇━━━━━━╇━━━━━━━━━━━━━━━━━━┩
│ 2 │ Beta │ beta@example.com │
└────┴──────┴──────────────────┘Pattern match (LIKE) in a specific column
bash
dbgrep --config config.json search --in users.email --like "%@example.com"bash
Table: users
┏━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ id ┃ name ┃ email ┃
┡━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ 1 │ Alpha │ alpha@example.com │
│ 2 │ Beta │ beta@example.com │
│ 3 │ Gamma │ gamma@example.com │
│ 4 │ Delta │ delta@example.com │
│ 5 │ Epsilon │ epsilon@example.com │
│ 6 │ Zeta │ zeta@example.com │
│ 7 │ Eta │ eta@example.com │
│ 8 │ Theta │ theta@example.com │
└────┴─────────┴─────────────────────┘Values greater than a threshold (e.g., salary > 72000)
bash
dbgrep --config config.json search --in employees.salary --greater 72000bash
Table: employees
┏━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━┓
┃ id ┃ user_id ┃ department_id ┃ position ┃ salary ┃ hire_date ┃ active ┃
┡━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━┩
│ 1 │ 1 │ 1 │ Senior Developer │ 85000.0 │ 2021-03-15 │ True │
│ 4 │ 4 │ 1 │ Research Scientist │ 92000.0 │ 2020-05-20 │ True │
│ 5 │ 5 │ 4 │ Financial Analyst │ 78000.0 │ 2019-11-15 │ - │
│ 6 │ 6 │ 5 │ Research Director │ 110000.0 │ 2018-03-10 │ True │
│ 8 │ 8 │ 7 │ Sales Representative │ 75000.0 │ 2022-02-14 │ True │
└────┴─────────┴───────────────┴──────────────────────┴──────────┴────────────┴────────┘Values less than a threshold (e.g., salary < 66000)
bash
dbgrep --config config.json search --in employees.salary --less 66000bash
┏━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━┓
┃ id ┃ user_id ┃ department_id ┃ position ┃ salary ┃ hire_date ┃ active ┃
┡━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━┩
│ 2 │ 2 │ 2 │ Marketing Specialist │ 65000.0 │ 2022-01-10 │ True │
└────┴─────────┴───────────────┴──────────────────────┴─────────┴────────────┴────────┘Combined search: LIKE and GREATER
bash
dbgrep --config config.json search --in employees.position --like "%Manager%" --greater 50000bash
Table: employees
┏━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━┓
┃ id ┃ user_id ┃ department_id ┃ position ┃ salary ┃ hire_date ┃ active ┃
┡━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━┩
│ 3 │ 3 │ 3 │ HR Manager │ 72000.0 │ 2020-11-05 │ True │
└────┴─────────┴───────────────┴────────────┴─────────┴────────────┴────────┘