Postgres
Source:
src/SQL/Postgres.ts
Open an @effect/sql-pg client (a connection pool) from a connection URL.
Accepts a plain Redacted URL or an Effect of one — e.g.
Cloudflare.Hyperdrive.Connect(...)’s connectionString — and returns a
PgClient (which implements the generic SqlClient interface) wrapped in
a chainable Proxy, so it can be resolved once at init and used from any
handler:
import * as SQL from "alchemy/SQL";
const hd = yield* Cloudflare.Hyperdrive.Connect(Hyperdrive);const sql = yield* SQL.Postgres({ url: hd.connectionString });
fetch: Effect.gen(function* () { const users = yield* sql`SELECT * FROM users`;});The pool is built lazily on the first query and memoized on the current
execution’s Scope (via makeExecutionMemo), so it’s created at
most once per execution — a Worker fetch/queue/scheduled event, a
Durable Object call, a Workflow run, or a Lambda invocation — and its
end finalizer fires when the event settles. Yielding the connection URL
is likewise deferred, so deploy / plan-time invocations never connect.