Back to Skills

query-builder

verified

Convert natural language questions into SQL queries. Activates when users ask data questions in plain English like "show me users who signed up last week" or "find orders over $100".

View on GitHub

Repository
Verified Org

clidey/whodb
4.5kstars

cli/skills/query-builder/SKILL.md

Last Verified

January 18, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/clidey/whodb/blob/efc91ff33564a10199d2870bdadeef0fcaec3b48/cli/skills/query-builder/SKILL.md -a claude-code --skill query-builder

Installation paths:

Claude
.claude/skills/query-builder/
Powered by add-skill CLI

Instructions

# Query Builder

Convert natural language questions into SQL queries using the database schema.

## When to Use

Activate when user asks questions like:
- "Show me all users who signed up last month"
- "Find orders greater than $100"
- "Which products have low inventory?"
- "Get the top 10 customers by total spend"

## Workflow

### 1. Understand the Schema
Before generating SQL, always check the table structure:

```
whodb_tables(connection="...") → Get available tables
whodb_columns(table="relevant_table") → Get column names and types
```

### 2. Identify Intent
Parse the natural language request:
- **Subject**: What entity? (users, orders, products)
- **Filter**: What conditions? (last month, > $100, active)
- **Aggregation**: Count, sum, average, max, min?
- **Grouping**: By what dimension?
- **Ordering**: Sort by what? Ascending/descending?
- **Limit**: How many results?

### 3. Map to Schema
- Match entities to table names
- Match attributes to column names
- Identify foreign key joins needed

### 4. Generate SQL
Build the query following SQL best practices:

```sql
SELECT columns
FROM table
[JOIN other_table ON condition]
WHERE filters
[GROUP BY columns]
[HAVING aggregate_condition]
ORDER BY column [ASC|DESC]
LIMIT n;
```

### 5. Execute and Present
```
whodb_query(query="generated SQL")
```

## Translation Patterns

| Natural Language | SQL Pattern |
|------------------|-------------|
| "last week/month/year" | `WHERE date_col >= DATE_SUB(NOW(), INTERVAL 1 WEEK)` |
| "more than X" / "greater than X" | `WHERE col > X` |
| "top N" | `ORDER BY col DESC LIMIT N` |
| "how many" | `SELECT COUNT(*)` |
| "total" / "sum of" | `SELECT SUM(col)` |
| "average" | `SELECT AVG(col)` |
| "for each" / "by" | `GROUP BY col` |
| "between X and Y" | `WHERE col BETWEEN X AND Y` |
| "contains" / "like" | `WHERE col LIKE '%term%'` |
| "starts with" | `WHERE col LIKE 'term%'` |
| "is empty" / "is null" | `WHERE col IS NULL` |
| "is not empty" | `WHERE col IS NOT NULL` |

## Date Ha

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
3135 chars