ancoleman/using-relational-databases
Relational database implementation across Python, Rust, Go, and TypeScript. Use when building CRUD applications, transactional systems, or structured data storage. Covers PostgreSQL (primary), MySQL, SQLite, ORMs (SQLAlchemy, Prisma, SeaORM, GORM), query builders (Drizzle, sqlc, SQLx), migrations, connection pooling, and serverless databases (Neon, PlanetScale, Turso).
npx skills add https://github.com/ancoleman/ai-design-components --skill using-relational-databases
This skill guides relational database selection and implementation across multiple languages. Choose the optimal database engine, ORM/query builder, and deployment strategy for transactional systems, CRUD applications, and structured data storage.
Trigger this skill when:
Skip this skill for:
Database Selection Decision Tree
═══════════════════════════════════════════════════════════
PRIMARY CONCERN?
├─ MAXIMUM FLEXIBILITY & EXTENSIONS (JSON, arrays, vector search)
│ └─ PostgreSQL
│ ├─ Serverless → Neon (scale-to-zero, database branching)
│ └─ Traditional → Self-hosted, AWS RDS, Google Cloud SQL
│
├─ EMBEDDED / EDGE DEPLOYMENT (local-first, global latency)
│ └─ SQLite or Turso
│ ├─ Global distribution → Turso (libSQL, edge replicas)
│ └─ Local-only → SQLite (embedded, zero-config)
│
├─ LEGACY SYSTEM / MYSQL REQUIRED
│ └─ MySQL
│ ├─ Serverless → PlanetScale (non-blocking migrations)
│ └─ Traditional → Self-hosted, AWS RDS, Google Cloud SQL
│
└─ RAPID PROTOTYPING
├─ Python → SQLModel (FastAPI) or SQLAlchemy 2.0
├─ TypeScript → Prisma (best DX) or Drizzle (performance)
├─ Rust → SQLx (compile-time checks)
└─ Go → sqlc (type-safe code generation)
ORM vs Query Builder Selection
═══════════════════════════════════════════════════════════
TEAM PRIORITIES?
├─ DEVELOPMENT SPEED / DEVELOPER EXPERIENCE
│ └─ ORM (abstracts SQL, handles relations automatically)
│ ├─ Python → SQLAlchemy 2.0, SQLModel
│ ├─ TypeScript → Prisma (migrations, type generation)
│ ├─ Rust → SeaORM (Active Record + Data Mapper)
│ └─ Go → GORM, Ent
│
├─ PERFORMANCE / QUERY CONTROL
│ └─ Query Builder (SQL-like, zero abstraction overhead)
│ ├─ Python → SQLAlchemy Core, asyncpg
│ ├─ TypeScript → Drizzle, Kysely
│ ├─ Rust → SQLx (compile-time query validation!)
│ └─ Go → sqlc (generates types from SQL)
│
├─ TYPE SAFETY / COMPILE-TIME GUARANTEES
│ ├─ Rust → SQLx (queries checked at build time)
│ ├─ Go → sqlc (generates types from SQL)
│ ├─ TypeScript → Prisma or Drizzle
│ └─ Python → SQLModel (Pydantic integration)
│
└─ COMPLEX QUERIES / JOINS
├─ SQL-first → Query builders or raw SQL
└─ ORM-friendly → SeaORM, SQLAlchemy ORM
Recommended Libraries:
/websites/sqlalchemy_en_21) - ORM + Core, 7,090 snippetsWhen to Use:
Quick Pattern:
from sqlmodel import SQLModel, Field, Session
class User(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True)
email: str = Field(unique=True, index=True)
See: references/orms-python.md for complete SQLAlchemy/SQLModel patterns, async workflows, and connection pooling.
Recommended Libraries:
/prisma/prisma, score: 96.4, 4,281 doc snippets) - Best DX, migrations/drizzle-team/drizzle-orm-docs, score: 95.4, 4,037 snippets) - Performance, SQL-likeQuick Comparison:
See: references/orms-typescript.md for Prisma vs Drizzle detailed comparison, Kysely, TypeORM patterns.
Recommended Libraries:
Quick Pattern:
use sqlx::FromRow;
#[derive(FromRow)]
struct User { id: i32, email: String, name: String }
// Compile-time checked queries (verified at build time!)
let user = sqlx::query_as::<_, User>("SELECT * FROM users WHERE email = $1")
.bind("[email protected]").fetch_one(&pool).await?;
See: references/orms-rust.md for SQLx macros, SeaORM, Diesel patterns, and compile-time guarantees.
Recommended Libraries:
Quick Pattern:
-- queries.sql: SQL annotations generate type-safe Go code
-- name: CreateUser :one
INSERT INTO users (email, name) VALUES ($1, $2) RETURNING *;
user, err := queries.CreateUser(ctx, db.CreateUserParams{Email: "[email protected]"})
See: references/orms-go.md for sqlc setup, GORM, Ent, and pgx patterns.
Recommended Pool Sizes:
See: references/connection-pooling.md for configuration examples, sizing formulas, and monitoring strategies.
Critical Principles:
CREATE INDEX CONCURRENTLY (PostgreSQL) to avoid blocking writesTools: Alembic (Python), Prisma Migrate (TypeScript), SQLx migrations (Rust), golang-migrate (Go)
See: references/migrations-guide.md for safe migration patterns, multi-phase deployments, and rollback strategies.
| Database | Type | Key Feature | Best For |
|----------|------|-------------|----------|
| Neon | PostgreSQL | Database branching, scale-to-zero | Development workflows, preview environments |
| PlanetScale | MySQL (Vitess) | Non-blocking schema changes | MySQL apps, zero-downtime migrations |
| Turso | SQLite (libSQL) | Edge deployment, low latency | Edge functions, global distribution |
See: references/serverless-databases.md for setup examples, branching workflows, and cost comparisons.
Common Integration Patterns:
See working examples in: examples/python-sqlalchemy/, examples/typescript-drizzle/, examples/rust-sqlx/
references/postgresql-guide.md - PostgreSQL features (pgvector, PostGIS, TimescaleDB)references/mysql-guide.md - MySQL-specific patterns, PlanetScale integrationreferences/sqlite-guide.md - SQLite patterns, Turso edge deploymentreferences/orms-python.md - SQLAlchemy 2.0, SQLModel, asyncpgreferences/orms-typescript.md - Prisma, Drizzle, Kysely comparisonsreferences/orms-rust.md - SQLx, SeaORM, Dieselreferences/orms-go.md - GORM, sqlc, Ent, pgxreferences/migrations-guide.md - Safe schema evolution patternsreferences/connection-pooling.md - Pool sizing and monitoringreferences/serverless-databases.md - Neon, PlanetScale, Turso deploymentexamples/python-sqlalchemy/ - SQLAlchemy 2.0 + FastAPI with pooling, migrationsexamples/typescript-prisma/ - Prisma + Next.js with schema, migrationsexamples/typescript-drizzle/ - Drizzle + Hono with type-safe queriesexamples/rust-sqlx/ - SQLx + Axum with compile-time checksexamples/go-sqlc/ - sqlc + Gin with generated type-safe codescripts/validate_schema.py - Validate database schema structure, constraintsscripts/generate_migration.py - Generate migration templates for common operationsSecurity:
Performance:
EXPLAIN ANALYZE for slow queriesReliability:
Development:
Take ancoleman/using-relational-databases from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.