D1
Source:
src/SQL/D1.ts
Open an @effect/sql-d1 client over a Cloudflare D1 binding.
Accepts the client returned by Cloudflare.D1.QueryDatabase(db) — or its
raw effect directly — and returns a D1Client (which implements the
generic SqlClient interface) wrapped in a chainable Proxy, so it can be
resolved once at Worker init and used from any handler:
import * as SQL from "alchemy/SQL";
const d1 = yield* Cloudflare.D1.QueryDatabase(Db);const sql = yield* SQL.D1(d1);
fetch: Effect.gen(function* () { const users = yield* sql`SELECT * FROM users`;});The client build is deferred until the first query and memoized on the
current execution’s Scope (via makeExecutionMemo), so the
D1Client (and its prepared-statement cache) is built at most once per
execution — a Worker fetch/queue/scheduled event, a Durable Object
call, or a Workflow run — and torn down when the event settles. Deploy /
plan-time invocations never touch D1.