Connect
Source:
src/Prisma/Connect.ts
Bind a Connection to a Prisma Compute app, AWS Lambda Function,
Cloudflare Worker, or Cloudflare Container and obtain the typed runtime
client.
Connect is a single identifier that is simultaneously the binding’s
Context tag, its type, and the callable —
yield* Prisma.Connect(connection).
Provide Prisma.ConnectBinding on the host implementation so Alchemy can
register the deploy-time binding and resolve the client at runtime.
Binding a Connection
Section titled “Binding a Connection”Use a connection inside Prisma Compute
export default Prisma.Compute( "api", { project, main: import.meta.filename }, 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)),);Use a connection inside a Cloudflare Container
export default Api.make( { main: import.meta.url }, Effect.gen(function* () { const db = yield* Prisma.Connect(connection); const sql = yield* SQL.Postgres({ url: db.databaseUrl });
return Api.of({ fetch: Effect.gen(function* () { const users = yield* sql`SELECT * FROM users`; return yield* HttpServerResponse.json(users); }), }); }).pipe(Effect.provide(Prisma.ConnectBinding)),);A container is a real process with no workerd bindings, so the connection
travels as plain environment variables — the same channel Prisma Compute
and Lambda use. Start the container with
Cloudflare.Containers.layer(Api, { enableInternet: true }) so it can
reach the database. (Hyperdrive, by contrast, is a workerd binding and is
unavailable inside a container.)