SQL
An alchemy app talks SQL at whichever level fits: a raw
tagged-template client, an ORM, or both against the same connection.
The schema rides the same deploy graph as the infrastructure, so
alchemy deploy regenerates and applies pending migrations alongside
everything else.
Databases
Section titled “Databases”- D1 — Cloudflare’s serverless SQLite, bound natively into a Worker.
- Hyperdrive — edge connection pooling for any Postgres or MySQL: Neon, PlanetScale, RDS, or a database you already run.
- AWS-side connections — DSQL, RDS, and Redshift bindings in the API reference.
Clients
Section titled “Clients”alchemy/SQL/* is the low-level home: tagged-template queries with
typed errors, no ORM — one subpath per backend (alchemy/SQL/D1,
alchemy/SQL/Postgres, alchemy/SQL/MySQL), so you only load the
driver you use.
alchemy/Drizzle is the ORM sibling: a typed schema and relational
queries. Drizzle.Schema, Drizzle.providers(), and Drizzle.D1
come from the alchemy/Drizzle entry; the Postgres and MySQL
clients live on their own subpaths (alchemy/Drizzle/Postgres,
alchemy/Drizzle/MySQL) so their drivers only load when you use
them, and the Durable Object client lives at
alchemy/Drizzle/Cloudflare. Both wrap the same
@effect/sql drivers and share one
lifecycle.
import * as SQL from "alchemy/SQL/D1";import * as Drizzle from "alchemy/Drizzle";
// Raw effect-sql — tagged-template queries, typed errorsconst sql = yield* SQL.D1(d1);const users = yield* sql`SELECT * FROM users WHERE id = ${id}`;
// Drizzle — typed schema, relational queriesconst db = yield* Drizzle.D1(d1, { relations });const user = yield* db.query.Users.findFirst({ with: { posts: true } });Every client builds lazily on the first query of an execution, is reused for every query in that execution, and tears down when the event settles — Connection lifecycle explains why.
What are you building?
Section titled “What are you building?”| Goal | Reach for |
|---|---|
| Raw SQL on Postgres | Effect SQL: Postgres |
| Raw SQL on MySQL | Effect SQL: MySQL |
| Raw SQL on D1 | Effect SQL: D1 |
| Typed schema + queries on Postgres | Drizzle: Postgres |
| Typed schema + queries on MySQL | Drizzle: MySQL |
| Typed schema + queries on D1 | Drizzle: D1 |
| Schema changes applied on deploy | Drizzle migrations |
Hand-written .sql migrations |
Effect SQL migrations |
| A service that runs on any database | SqlClient + Layers — see Provide as a service |
Where next
Section titled “Where next”- Effect SQL: Postgres / MySQL / D1 — the raw clients.
- Drizzle: Postgres / MySQL / D1 — schema to queries, end to end.
- Add Drizzle ORM — full Worker wiring on Postgres via Hyperdrive.
- Drizzle on D1 — full Worker wiring on D1.
- API reference — every SQL and Drizzle export.