sqlmodel-database

Design SQLModel database schemas for FastAPI with Neon PostgreSQL connections.

27|11|Updated Dec 21, 2025
One-click install
npx skills add https://github.com/mjunaidca/mjs-agent-skills --skill sqlmodel-database
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sqlmodel-database
Source: https://github.com/mjunaidca/mjs-agent-skills/tree/main/docs/taskflow-vault/skills/engineering/sqlmodel-database
Command: npx skills add https://github.com/mjunaidca/mjs-agent-skills --skill sqlmodel-database

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you design and implement database schemas using SQLModel, covering sync and async patterns, Neon PostgreSQL connections, relationships (one-to-many, many-to-many), and FastAPI dependency injection.

Core Features & Use Cases

  • Model Hierarchy: Define base models, table models (with id and timestamps), and read/create/update variants.
  • Sync & Async DB Connections: Demonstrate both Session (sync) and AsyncSession (async) usage and setup.
  • API Integration: Generate API schemas from models and wire FastAPI dependencies for sessions.

Quick Start

Create a sample Task model with TaskCreate/TaskRead and perform a basic CRUD using SQLModel with a Neon PostgreSQL database.

Frequently Asked Questions about sqlmodel-database

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

FAQPage Schema
How do I design database schemas with SQLModel for FastAPI applications?

SQLModel lets you define database schemas by creating model classes that inherit from SQLModel's base, specifying columns with type hints, and establishing relationships. You define a hierarchy of base models, table models with id and timestamps, and API variants (Create, Read, Update) to separate database and API concerns within FastAPI apps.

Can I use SQLModel with both sync and async database operations?

Yes. SQLModel supports both sync operations using Session and async operations using AsyncSession. You configure either pattern depending on your FastAPI application's needs, manage session lifecycle through dependency injection, and write async-compatible queries for high-concurrency workloads.

How do I set up one-to-many and many-to-many relationships in SQLModel?

Define relationships using SQLModel's Relationship field with foreign key constraints and back_populates parameters. Establish one-to-many by linking child models to a parent via foreign key, and many-to-many using association tables, then wire them into FastAPI endpoints through dependency injection.

What's the best way to connect SQLModel to a PostgreSQL database like Neon?

Create a database engine using SQLAlchemy with a PostgreSQL connection string, instantiate Session or AsyncSession from it, and inject sessions into FastAPI route handlers via Depends. This pattern keeps connections managed centrally while routes stay clean and testable.

Do I need Alembic to manage SQLModel database migrations?

Alembic is the standard tool for managing schema migrations with SQLModel. It tracks model changes, generates migration scripts, and applies them to your PostgreSQL database, ensuring schema versions stay in sync across environments.

How do I generate API schemas from SQLModel models in FastAPI?

SQLModel models automatically generate OpenAPI schemas when used as FastAPI request/response types. Define separate model classes for Create, Read, and Update operations, use them in route decorators, and FastAPI generates correct documentation and validation without extra configuration.