Skip to content

Effect SQLType-safe, composable SQL for Effect

Write SQL queries that are safe, efficient, and integrate seamlessly with the Effect ecosystem

Quick Example

typescript
import { Effect } from "effect"
import { SqlClient } from "@effect/sql"
import { PgClient } from "@effect/sql-pg"

// Create a query - it's just a tagged template literal
const findUserById = (id: number) =>
  Effect.gen(function* () {
    const sql = yield* SqlClient.SqlClient
    
    const users = yield* sql<{ id: number; name: string; email: string }>`
      SELECT id, name, email 
      FROM users 
      WHERE id = ${id}
    `
    
    return users[0]
  })

// Run with proper resource management
const program = findUserById(1).pipe(
  Effect.provide(PgClient.layer({
    host: "localhost",
    database: "myapp"
  }))
)

Effect.runPromise(program)

Why Effect SQL?

Effect SQL is designed from the ground up to work with the Effect ecosystem. This means:

  • Automatic resource management - Connections are acquired and released automatically
  • Structured error handling - SQL errors are properly typed and handled
  • Observability built-in - Queries emit spans for tracing automatically
  • Composable - Build complex queries from simple, reusable pieces
Ready to dive in? Start with the Introduction to learn the fundamentals.

Released under the MIT License.