Type-Safe by Design
Write SQL with full TypeScript type safety. Catch errors at compile time, not runtime. Integrate with Effect Schema for validated, decoded results.
Write SQL queries that are safe, efficient, and integrate seamlessly with the Effect ecosystem
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)Effect SQL is designed from the ground up to work with the Effect ecosystem. This means: