effect-sql

Implements type-safe SQL queries, repositories, resolvers, and migrations with Effect TypeScript.

1|Updated Aug 24, 2026
One-click install
npx skills add https://github.com/lambdasolver2/opencode-effect-harness --skill effect-sql-lambdasolver2
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: effect-sql
Source: https://github.com/lambdasolver2/opencode-effect-harness/tree/main/packages/module-typescript/assets/skills/effect-sql
Command: npx skills add https://github.com/lambdasolver2/opencode-effect-harness --skill effect-sql-lambdasolver2

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires effect, @effect/sql-pg, @effect/sql-pglite, @effect/sql-mysql2, @effect/sql-sqlite-node, @effect/sql-libsql, @effect/sql-mssql, @effect/sql-clickhouse.

What problem does it solve? Writing database access code in TypeScript often means untyped query results, manual SQL string building, N+1 query problems, and ad-hoc migration handling. This Skill provides expert guidance for building type-safe SQL layers with the Effect v4 SQL modules, covering everything from raw queries to full CRUD repositories. ## Core Features & Use Cases - SqlClient Tagged Templates: Build parameterized queries with safe interpolation, insert/update helpers, transactions with automatic savepoints, and dialect branching for PostgreSQL, MySQL, SQLite, MSSQL, and ClickHouse. - SqlSchema & SqlModel: Validate query inputs and outputs with Effect Schema, define Model classes with select/insert/update/JSON variants, and generate complete CRUD repositories with soft-delete support. - SqlResolver & 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: You are building a PostgreSQL-backed service in Effect. Use this Skill to define a User model with branded IDs and auto-timestamps, generate a repository with SqlModel.makeRepository, batch lookups with resolvers, and wire up migrations through the PgClient layer. ## Quick Start Ask the assistant to create an Effect SQL repository for a users table with a Model class, CRUD operations, and a migration file using the PgClient layer.

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 parameterized queries, and wrap queries with SqlSchema.findOne, findAll, or void to validate requests and decode results through Effect Schema. This gives typed rows instead of untyped driver output.

How do I create 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 softDeleteColumn.

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 via Effect.yieldNow.

Which databases does Effect SQL support?

Effect SQL supports PostgreSQL via @effect/sql-pg, embedded PostgreSQL via @effect/sql-pglite, MySQL via @effect/sql-mysql2, SQLite via @effect/sql-sqlite-node, libSQL/Turso via @effect/sql-libsql, Microsoft SQL Server via @effect/sql-mssql, and ClickHouse via @effect/sql-clickhouse.

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.

When should I use raw SqlClient queries instead of SqlModel repositories?

Use raw SqlClient tagged templates for custom joins, aggregations, or dialect-specific features that repositories do not cover. Wrap them in SqlSchema for validated I/O, and reserve SqlModel repositories for standard CRUD operations on single tables.