Build Your Database Skill

Create a relational-db-agent skill that knows SQLModel async patterns

181 stars

Best use case

Build Your Database Skill is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Create a relational-db-agent skill that knows SQLModel async patterns

Teams using Build Your Database Skill should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/44-relational-databases-sqlmodel/SKILL.md --create-dirs "https://raw.githubusercontent.com/majiayu000/claude-skill-registry/main/skills/data/44-relational-databases-sqlmodel/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/44-relational-databases-sqlmodel/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How Build Your Database Skill Compares

Feature / AgentBuild Your Database SkillStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Create a relational-db-agent skill that knows SQLModel async patterns

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Build Your Database Skill

You're about to learn async database patterns with SQLModel. But you won't start with "what is SQLModel?"

You'll start by **building a skill that knows SQLModel**.

This is the skill-first approach: instead of accumulating knowledge that fades, you create an asset that grows. By chapter end, your `relational-db-agent` skill will generate production-quality database code—and you'll own it.

## Why Skill-First for Databases?

Database patterns are precise. Off-by-one errors in async patterns cause `MissingGreenlet` crashes. Forgotten `await` keywords block your entire agent. Wrong relationship configurations cascade into N+1 query disasters.

A skill that knows the correct patterns eliminates these errors. You consult your skill, it generates correct code, you ship faster.

## Step 1: Clone the Skills Lab

Start fresh. Every chapter begins with a clean skills-lab:

```bash
cd ~/projects
git clone https://github.com/panaversity/claude-code-skills-lab.git ch44-skills-lab
cd ch44-skills-lab
```

**Output:**
```
Cloning into 'ch44-skills-lab'...
remote: Enumerating objects: 45, done.
remote: Counting objects: 100% (45/45), done.
Receiving objects: 100% (45/45), done.
```

## Step 2: Write Your Learning Specification

Before building the skill, define what it should know. Create `LEARNING-SPEC.md`:

```markdown
# Learning Specification: Relational Database Skill

## What This Skill Should Know

### Core Patterns
- Async engine creation with `create_async_engine`
- Connection pooling for production (`pool_pre_ping`, `pool_size`)
- AsyncSession from `sqlmodel.ext.asyncio.session`
- Session lifecycle as FastAPI dependency

### Model Patterns
- SQLModel with `table=True`
- JSONB columns for PostgreSQL
- Foreign keys and relationships
- Self-referential relationships (parent/child)

### Operations
- Async CRUD (add, flush, commit, refresh)
- Eager loading with `selectinload`
- Transaction patterns (rollback on error)

### Migrations
- Alembic async template
- Model import requirements
- Autogenerate and upgrade commands

## Success Criteria
The skill generates code that:
1. Compiles without syntax errors
2. Uses correct async/await patterns
3. Includes proper imports
4. Follows SQLModel conventions
```

**Output:**
```
Created LEARNING-SPEC.md (32 lines)
```

## Step 3: Fetch Official Documentation

Use the `/fetching-library-docs` command to get accurate patterns:

```
/fetching-library-docs sqlmodel --topic "async session"
```

The skill retrieves official SQLModel patterns—imports, code examples, and usage notes.

**What you'll receive:**
- `create_async_engine` syntax
- `AsyncSession` import path
- Session lifecycle patterns
- Code examples from official docs

Save the key patterns for your skill. Don't memorize—capture.

## Step 4: Create Your Skill

Use `/skill-creator` to build the `relational-db-agent` skill:

```
/skill-creator relational-db-agent

The skill should:
- Generate async SQLModel code for FastAPI backends
- Know proper async engine and session patterns
- Include PostgreSQL-specific features like JSONB
- Prevent common async pitfalls (MissingGreenlet, N+1 queries)
- Reference SQLModel and SQLAlchemy 2.0 async patterns

Use the patterns from LEARNING-SPEC.md and the fetched documentation.
```

The skill creator generates:
- `SKILL.md` with triggering description and instructions
- `references/` directory for detailed patterns
- `scripts/verify.py` for validation

**Output:**
```
✓ Created .claude/skills/relational-db-agent/SKILL.md
✓ Created .claude/skills/relational-db-agent/references/async-patterns.md
✓ Created .claude/skills/relational-db-agent/scripts/verify.py
```

## Step 5: Test Your Skill

Verify your skill generates valid code:

```
Using my relational-db-agent skill, create a Task model with:
- id as primary key
- title as string
- status as string with default "pending"
- created_at timestamp
```

**Expected output:**

```python
from sqlmodel import SQLModel, Field
from datetime import datetime

class Task(SQLModel, table=True):
    id: int | None = Field(default=None, primary_key=True)
    title: str
    status: str = Field(default="pending")
    created_at: datetime = Field(default_factory=datetime.utcnow)
```

If the output includes correct imports, `table=True`, and proper Field usage—your skill works.

## What Happens Next

| Lesson | You Learn | Your Skill Improves |
|--------|-----------|---------------------|
| L01 | Why agents need structured data | Understands relational vs vector DB |
| L02 | Async engine setup | Generates correct engine config |
| L03 | Model design | Handles JSONB and constraints |
| L04 | Session management | Knows AsyncSession lifecycle |
| L05 | CRUD operations | Generates proper async CRUD |
| L06 | Relationships | Includes selectinload patterns |
| L07 | Transactions | Handles rollback correctly |
| L08 | Migrations | Knows Alembic async setup |
| L09 | Complete layer | Generates full database layer |

Each lesson ends with a "Reflect on Your Skill" section where you test what you learned against your skill and improve it.

## Try With AI

### Prompt 1: Verify Your Skill Structure

```
Check my relational-db-agent skill at .claude/skills/relational-db-agent/
Does it have:
1. SKILL.md with proper YAML frontmatter
2. A description starting with "Use when"
3. References for async patterns
Suggest any improvements to the structure.
```

**What you're learning:** Skill validation—ensuring your skill follows the format that makes it discoverable and usable.

### Prompt 2: Test AsyncSession Generation

```
Using my relational-db-agent skill, generate a get_session()
FastAPI dependency that yields an AsyncSession from an async engine.
Include all necessary imports.
```

**What you're learning:** Session management patterns—the foundation of async database operations.

### Prompt 3: Identify Gaps

```
I'm about to learn SQLModel async patterns. Based on my
relational-db-agent skill, what database concepts should
I add to make it more complete? Consider:
- What async pitfalls is it missing?
- What PostgreSQL features should it know?
- What relationship patterns should it include?
```

**What you're learning:** Gap analysis—proactively identifying what your skill needs to become production-ready.

### Safety Note

Your skill will generate database code. Always review generated code before running it—especially CREATE, DROP, or migration operations. Test in development before production.

---

## Reflect on Your Skill

You created a `relational-db-agent` skill. Test it now.

### Test Your Skill

```
Using my relational-db-agent skill, generate a complete
async database setup for a FastAPI app with:
- PostgreSQL connection
- Engine with connection pooling
- get_session dependency
```

### Identify Gaps

Ask yourself:
- Did my skill include `pool_pre_ping=True`?
- Did it use `sqlmodel.ext.asyncio.session.AsyncSession`?
- Did it structure the dependency correctly with `yield`?

### Improve Your Skill

If you found gaps:

```
My relational-db-agent skill is missing connection pool configuration.
Update it to always include pool_pre_ping=True and configurable
pool_size for production deployments.
```

Your skill just got better. This pattern repeats every lesson.

Related Skills

admin-panel-builder

181
from majiayu000/claude-skill-registry

Expert assistant for creating and maintaining admin panel pages in the KR92 Bible Voice project. Use when creating admin pages, building admin components, integrating with admin navigation, or adding admin features.

adk-agent-builder

181
from majiayu000/claude-skill-registry

Build production-ready AI agents using Google's Agent Development Kit with AI assistant integration, React patterns, multi-agent orchestration, and comprehensive tool libraries. Use when appropriate context detected. Trigger with relevant phrases based on skill purpose.

add-database-table

181
from majiayu000/claude-skill-registry

Create database migrations, define table schemas, and manage constant tables (enums). Use when: (1) creating a new database table, (2) running 'make migrate.create', (3) adding enum/status values, (4) modifying table structure. REQUIRED first step before add-domain-entity.

adb-builder

181
from majiayu000/claude-skill-registry

No description provided.

action-builder-skill

181
from majiayu000/claude-skill-registry

Use when creating or refactoring Nango integration actions to be thin API wrappers - provides patterns for minimal transformation logic, direct proxy calls, and standardized structure

acsets-algebraic-databases

181
from majiayu000/claude-skill-registry

ACSets (Attributed C-Sets): Algebraic databases as in-memory data structures. Category-theoretic formalism for relational databases generalizing graphs and data frames.

acc-create-test-builder

181
from majiayu000/claude-skill-registry

Generates Test Data Builder and Object Mother patterns for PHP 8.5. Creates fluent builders with sensible defaults and factory methods for test data creation.

acc-create-builder

181
from majiayu000/claude-skill-registry

Generates Builder pattern for PHP 8.5. Creates step-by-step object construction with fluent interface and validation. Includes unit tests.

web-artifacts-builder

181
from majiayu000/claude-skill-registry

Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use for complex artifacts requiring state management, routing, or shadcn/ui components - not for simple single-file HTML/JSX artifacts.

Build Your LiveKit Agents Skill

181
from majiayu000/claude-skill-registry

Create your LiveKit Agents skill from official documentation, then learn to improve it throughout the chapter

Build Your Agent Integration Skill

181
from majiayu000/claude-skill-registry

Create your agent-integration skill from OpenAI SDK and LiteLLM documentation before learning framework integration

Build Your Model Serving Skill

181
from majiayu000/claude-skill-registry

Create your model-serving skill from Ollama documentation before learning deployment theory