sqlmodel

Build SQLModel-based FastAPI applications with models, CRUD, and Alembic migrations.

Updated Dec 4, 2025
One-click install
npx skills add https://github.com/jr2804/prompts --skill sqlmodel
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sqlmodel
Source: https://github.com/jr2804/prompts/tree/main/skills/database/sqlmodel
Command: npx skills add https://github.com/jr2804/prompts --skill sqlmodel

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires sqlmodel, and includes scripts (resource) and references (resource) components.

What problem does it solve?

The sqlmodel skill provides a structured, hands-on guide to building database-backed FastAPI applications with SQLModel, PostgreSQL, and SQLAlchemy. It helps teams design clean models, manage sessions, implement CRUD, run migrations with Alembic, and optimize performance.

Core Features & Use Cases

  • Model-driven API development: define SQLModel models, relationships, and request/response schemas for FastAPI endpoints.
  • Database operations: perform CRUD, complex queries, and migrations with a production-ready workflow.
  • Testing and performance: test against SQLite or PostgreSQL, and apply pooling and indexing best practices for scalable apps.

Quick Start

Use the sqlmodel skill to scaffold a FastAPI project with a User model, a Post model, and a PostgreSQL database configuration; then run migrations and start the API server.

Frequently Asked Questions about sqlmodel

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define SQLModel models and relationships for a FastAPI application?

To define SQLModel models for FastAPI, you create Python classes inheriting from SQLModel, specifying table names and fields, and establish relationships using Relationship configurations to link related records across PostgreSQL tables.

What is the best way to run database migrations with Alembic in a SQLModel FastAPI project?

The best way to run database migrations with Alembic in a SQLModel FastAPI project is to configure Alembic to import your SQLModel metadata, generate migration scripts from model changes, and apply them to your PostgreSQL database.

Can I use SQLModel with PostgreSQL for production-grade CRUD operations?

Yes, you can use SQLModel with PostgreSQL for production-grade CRUD operations by leveraging SQLAlchemy sessions to implement complex queries and applying pooling and indexing best practices for scalable FastAPI performance.

How do I test FastAPI endpoints that connect to a PostgreSQL database using SQLModel?

To test FastAPI endpoints using SQLModel, you can configure your test suite to run against a lightweight SQLite database or a dedicated PostgreSQL instance, executing CRUD operations within isolated database sessions to ensure clean test states.

Does SQLModel handle both database schema definitions and FastAPI request validation?

Yes, SQLModel handles both database schema definitions and FastAPI request validation by extending Pydantic, allowing you to define a single model class that serves as both the SQLAlchemy ORM table and the Pydantic validation schema.

What are the limitations of using SQLModel for complex database queries in FastAPI?

A limitation of using SQLModel for complex database queries in FastAPI is that it relies on underlying SQLAlchemy constructs, meaning highly advanced ORM operations may require direct SQLAlchemy session execution instead of native SQLModel abstractions.