Connections
A Prisma.Connection is a credential (an API key) for one
database. The name prop is optional — alchemy derives one from the
logical ID and appends the resource’s instance identity so
connections stay unambiguous — and every secret output is Redacted
so nothing prints in logs or plan output.
import * as Prisma from "alchemy/Prisma";
const connection = yield* Prisma.Connection("api", { database: postgres,});Connection outputs
Section titled “Connection outputs”connection.databaseUrl; // conventional app URL (pooled → direct → Accelerate)connection.directConnectionString; // direct Postgres URLconnection.pooledConnectionString; // pooled Postgres URLconnection.accelerateConnectionString; // Accelerate URL, when the database has oneconnection.origin; // parsed direct connection componentsconnection.pooledOrigin; // parsed pooled connection componentsdatabaseUrl is the serverless-safe default for application
traffic: it prefers the pooled endpoint, then direct, then
Accelerate. Pass it (and the direct URL for migration tooling)
straight into an app’s env:
const app = yield* Prisma.Compute("api", { project, path: "./app", env: { DATABASE_URL: connection.databaseUrl, DIRECT_URL: connection.directConnectionString, },});The origin shape
Section titled “The origin shape”origin and pooledOrigin are the same connections parsed into the
structured shape Postgres consumers like Cloudflare.Hyperdrive
accept — the same shape Neon branches and PlanetScale roles
materialize:
type PostgresOrigin = { scheme: "postgres" | "postgresql"; host: string; port: number; database: string; user: string; password: Redacted.Redacted<string>;};Hyperdrive is itself a pooler, so hand it the direct origin:
const hyperdrive = yield* Cloudflare.Hyperdrive.Connection("api-hd", { origin: connection.origin.as<Prisma.PostgresOrigin>(),});(The .as<...>() narrows the output: a connection to a legacy
Accelerate-only database has no direct Postgres endpoint, so
origin is typed optional.)
The Connect binding
Section titled “The Connect binding”Inside a Prisma Compute app, AWS Lambda function, or Cloudflare
Worker, Prisma.Connect resolves the bound connection at runtime as
a typed client:
Effect.gen(function* () { const db = yield* Prisma.Connect(connection); const sql = yield* SQL.Postgres({ url: db.databaseUrl });
return { fetch: Effect.gen(function* () { const users = yield* sql`SELECT * FROM users`; return yield* HttpServerResponse.json(users); }), };}).pipe(Effect.provide(Prisma.ConnectBinding));At deploy time the binding carries the connection’s outputs into the
host’s environment (env vars on Compute and Lambda, secret text
bindings on Workers); at runtime db.databaseUrl and friends read
them back as Redacted values.
Rotation
Section titled “Rotation”Set rotate: true to mint fresh credentials on the next deploy
while keeping the connection’s identity:
const connection = yield* Prisma.Connection("api", { database: postgres, rotate: true,});Rotation revokes the previous key, so downstream consumers pick up the new secret on the same deploy through their bindings.
Where next
Section titled “Where next”- Connect from Workers — both wiring styles for Cloudflare, side by side.
- Hyperdrive — the full pooling walkthrough.
Reference: