effect-sql

Implements type-safe SQL queries, repositories, resolvers, and migrations using Effect SQL modules.

3|Updated Apr 1, 2026
One-click install
npx skills add https://github.com/mpsuesser/opencode-effect-enforcer --skill effect-sql-mpsuesser
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: effect-sql
Source: https://github.com/mpsuesser/opencode-effect-enforcer/tree/main/skills/effect-sql
Command: npx skills add https://github.com/mpsuesser/opencode-effect-enforcer --skill effect-sql-mpsuesser

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing database code in TypeScript often means untyped query results, manual SQL string building, N+1 query problems, and ad-hoc migration handling. This Skill guides an agent to build type-safe database access with Effect's SQL modules, covering validated queries, generated CRUD repositories, batched resolvers, and transactional migrations. ## Core Features & Use Cases - SqlClient tagged-template queries: Write parameterized queries with safe interpolation, insert/update helpers, transactions with automatic savepoints, dialect branching, and streaming for large result sets. - SqlSchema and SqlModel: Validate query inputs and outputs with Effect Schema, define Model classes with select/insert/update/JSON variants, and generate full CRUD repositories including soft deletes. - SqlResolver and Migrator: Batch requests to eliminate N+1 queries with ordered, findById, grouped, and void resolvers, and run sequential transactional migrations from filesystem, glob, or inline loaders. - Use Case: When building a PostgreSQL-backed service, use this Skill to define a User model, generate a repository with SqlModel.makeRepository, run migrations with Migrator, and wire everything through a PgClient layer. ## Quick Start Ask the agent to create an Effect SQL repository for a users table with a Model class, migrations, and a PgClient layer using this skill.

Frequently Asked Questions about effect-sql

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

FAQPage Schema
How do I write type-safe SQL queries in Effect TypeScript?▼

Use the SqlClient service as a tagged template literal, for example sql`SELECT * FROM users WHERE id = ${userId}`. Values are safely interpolated as parameters, and helpers like sql.insert and sql.update build INSERT and UPDATE statements without manual string concatenation.

How do I generate a CRUD repository with Effect SqlModel?▼

Define a Model.Class with field variants, then call SqlModel.makeRepository with the table name, span prefix, and id column. The generated repository provides insert, update, findById, and delete operations, with optional soft-delete support via the softDeleteColumn option.

Which databases does Effect SQL support?▼

Effect SQL provides driver packages for PostgreSQL (@effect/sql-pg), embedded PGlite, MySQL via mysql2, SQLite via better-sqlite3, libSQL/Turso, Microsoft SQL Server, and ClickHouse. Each driver layer provides both a driver-specific service and the generic SqlClient service.

How do I solve N+1 query problems with Effect SQL?▼

Use SqlResolver to create batched request resolvers: ordered for positional results, findById for key-matched lookups, grouped for one-to-many results, and void for side-effect-only operations. Resolvers batch concurrently queued requests by default, with setDelay and batchN for tuning.

How do database migrations work in Effect SQL?▼

The Migrator module runs sequential transactional migrations tracked in an effect_sql_migrations table. Migration files follow the id_name.ts naming convention and export a default Effect, loaded via fromFileSystem, fromGlob, fromRecord, or fromBabelGlob loaders.

Why should I avoid string concatenation in Effect SQL queries?▼

Manual string concatenation bypasses parameterization and risks SQL injection. Always use tagged template interpolation or sql.unsafe with explicit parameter arrays, and use sql.insert and sql.update helpers instead of listing columns and values by hand.