SQL
@alchemy.run/sql is how Alchemy apps use SQL databases, on every cloud. You declare the database, its migrations run on deploy, and your code queries it with Effect SQL, Drizzle or Prisma ORM over a connection that lasts one request.
New here? How SQL works in Alchemy walks through databases, clients, connections, pools and migrations, once each.
Choose a database
Section titled “Choose a database”See Databases to compare engines and connection paths, with links directly to each database’s setup guide.
Choose a client
Section titled “Choose a client”| Client | Guides |
|---|---|
| Effect SQL | Postgres · MySQL · D1 · libSQL · Durable Objects |
| Drizzle | Postgres · MySQL · D1 · libSQL · Durable Objects |
| Prisma ORM v8 | Contracts · Postgres · Migrations |
Prisma ORM v8 requires PostgreSQL 17+ and is separate from the Prisma hosting provider.
Find an integration
Section titled “Find an integration”| Integration | Guide |
|---|---|
| Lambda + Aurora PostgreSQL + Drizzle | AWS |
| Lambda + Aurora DSQL + Drizzle | AWS |
| Workers + Neon or PlanetScale + Drizzle | Cloudflare |
| Workers + D1 + Drizzle | Cloudflare |
| Workers + Turso + Drizzle | Turso |
| Durable Objects + SQLite | Cloudflare |
| Fly Service + Postgres + Drizzle | Fly |
| Hetzner Service + external Postgres + Drizzle | Hetzner |
| Prisma Compute + Postgres + Drizzle | Prisma |
| Railway Service + Postgres + Drizzle | Railway |
| Railway Service + MySQL + Drizzle | Railway |
| Workers + Neon + Prisma ORM | Cloudflare |
See runnable examples for complete projects.
Already have a database?
Section titled “Already have a database?”import * as SQL from "@alchemy.run/sql/Postgres";import * as Config from "effect/Config";import * as Effect from "effect/Effect";
const query = Effect.gen(function* () { const sql = yield* SQL.Postgres({ url: Config.Redacted("DATABASE_URL") }); return yield* sql`SELECT 1 AS value`;});Run queries within the application’s execution scope, or use Effect.scoped in a standalone program; see connection lifecycle.
Manage schema changes
Section titled “Manage schema changes”Generate migrations when schemas change, stage and review the schema, SQL, and snapshots with git diff --cached, then commit them before deployment. Apply the committed files using the selected database’s workflow.