Querying the Database
When to Apply
Activate this skill whenever you need to read data from the database to answer a
question — especially anything about production data. Prefer this command over
the tinker, database-query, or database-schema Boost tools when the user asks
about prod, since those default to the local connection.
The agent:db command
Runs a query (SELECT, SHOW, DESCRIBE, DELETE, etc.) and prints the result.
php artisan agent:db "<query>"
Options
--format=json (default) — pretty-printed JSON, best for parsing the result yourself.
--format=table — classic console table, best when showing the result to the user.
--prod — run against the production database (the prod connection backed by
PROD_DB_URL). Without this flag the query runs against the local DB.
PROD_DB_URL holds a MySQL user with read-only grants, so any write —
INSERT, UPDATE, DELETE, DDL — fails with an access-denied error from the
server. That is deliberate, and it is the only thing enforcing read-only: the
command itself hands the query straight to PDO. If a prod write fails, the
guardrail is working; run it against the local connection, or ship it as a
migration or a release command. Never work around it.
Examples
# Local, JSON (default)
php artisan agent:db "select id, email from users limit 5"
# Local, human-readable table
php artisan agent:db --format=table "select count(*) as total from transactions"
# Production
php artisan agent:db --prod "select count(*) from users"
php artisan agent:db --prod --format=table "select status, count(*) from subscriptions group by status"
Guidelines
--prod is read-only by credentials, not by convention (see above), but it is still live customer data. Only run prod queries the
user explicitly asked for, keep them scoped (add LIMIT, filter by id), and never
dump large or sensitive datasets unprompted. This app is privacy-first.
- Use
--format=json when you need to read the values to continue working; use
--format=table when presenting results back to the user.
- Inspect schema first with
database-schema (local) when you're unsure of column
names before writing a query.
1---2name: querying-the-database3description: Query the local or production database from the CLI via the `agent:db` artisan command. Activates when the user asks to inspect, count, look up, or run a query against the database; asks 'how many X', 'what's in prod', 'check the prod DB', 'query the database'; or mentions production data, the prod database, or running SQL.4---56# Querying the Database78## When to Apply910Activate this skill whenever you need to read data from the database to answer a11question — especially anything about **production** data. Prefer this command over12the `tinker`, `database-query`, or `database-schema` Boost tools when the user asks13about prod, since those default to the local connection.1415## The `agent:db` command1617Runs a query (`SELECT`, `SHOW`, `DESCRIBE`, `DELETE`, etc.) and prints the result.1819```bash20php artisan agent:db "<query>"21```2223### Options2425- `--format=json` (default) — pretty-printed JSON, best for parsing the result yourself.26- `--format=table` — classic console table, best when showing the result to the user.27- `--prod` — run against the **production** database (the `prod` connection backed by28 `PROD_DB_URL`). Without this flag the query runs against the local DB.2930 `PROD_DB_URL` holds a MySQL user with **read-only grants**, so any write —31 `INSERT`, `UPDATE`, `DELETE`, DDL — fails with an access-denied error from the32 server. That is deliberate, and it is the only thing enforcing read-only: the33 command itself hands the query straight to PDO. If a prod write fails, the34 guardrail is working; run it against the local connection, or ship it as a35 migration or a release command. Never work around it.3637### Examples3839```bash40# Local, JSON (default)41php artisan agent:db "select id, email from users limit 5"4243# Local, human-readable table44php artisan agent:db --format=table "select count(*) as total from transactions"4546# Production47php artisan agent:db --prod "select count(*) from users"48php artisan agent:db --prod --format=table "select status, count(*) from subscriptions group by status"49```5051## Guidelines5253- **`--prod` is read-only by credentials, not by convention** (see above), but it is still live customer data. Only run prod queries the54 user explicitly asked for, keep them scoped (add `LIMIT`, filter by id), and never55 dump large or sensitive datasets unprompted. This app is privacy-first.56- Use `--format=json` when you need to read the values to continue working; use57 `--format=table` when presenting results back to the user.58- Inspect schema first with `database-schema` (local) when you're unsure of column59 names before writing a query.