1---
2title: Connections
3description: Prisma Connections materialize database credentials — a conventional databaseUrl, direct and pooled connection strings, parsed origins for Hyperdrive, and the Connect runtime binding.
4---
5
6A `Prisma.Connection` is a credential (an API key) for one
7database. The `name` prop is optional — alchemy derives one from the
8logical ID and appends the resource's instance identity so
9connections stay unambiguous — and every secret output is `Redacted`
10so nothing prints in logs or plan output.
11
12```typescript
13import * as Prisma from "alchemy/Prisma";
14
15const connection = yield* Prisma.Connection("api", {
16 database: postgres,
17});
18```
19
20## Connection outputs
21
22```typescript
23connection.databaseUrl; // conventional app URL (pooled → direct → Accelerate)
24connection.directConnectionString; // direct Postgres URL
25connection.pooledConnectionString; // pooled Postgres URL
26connection.accelerateConnectionString; // Accelerate URL, when the database has one
27connection.origin; // parsed direct connection components
28connection.pooledOrigin; // parsed pooled connection components
29```
30
31`databaseUrl` is the serverless-safe default for application
32traffic: it prefers the pooled endpoint, then direct, then
33Accelerate. For a standalone database under a project created with
34`createDatabase: false`, pass it (and the direct URL for migration
35tooling) straight into an app's env:
36
37```typescript
38const app = yield* Prisma.Compute("api", {
39 project,
40 path: "./app",
41 env: {
42 DATABASE_URL: connection.databaseUrl,
43 DIRECT_URL: connection.directConnectionString,
44 },
45});
46```
47
48If `Prisma.Project` created the project's default database, omit
49these env entries. Prisma injects system-managed `DATABASE_URL` and
50`DATABASE_URL_POOLED` values into Compute deployments automatically.
51
52## The origin shape
53
54`origin` and `pooledOrigin` are the same connections parsed into the
55structured shape Postgres consumers like `Cloudflare.Hyperdrive`
56accept — the same shape Neon branches and PlanetScale roles
57materialize:
58
59```typescript
60type PostgresOrigin = {
61 scheme: "postgres" | "postgresql";
62 host: string;
63 port: number;
64 database: string;
65 user: string;
66 password: Redacted.Redacted<string>;
67};
68```
69
70Hyperdrive is itself a pooler, so hand it the **direct** origin:
71
72```typescript
73const hyperdrive = yield* Cloudflare.Hyperdrive.Connection("api-hd", {
74 origin: connection.origin.as<Prisma.PostgresOrigin>(),
75});
76```
77
78(The `.as<...>()` narrows the output: a connection to a legacy
79Accelerate-only database has no direct Postgres endpoint, so
80`origin` is typed optional.)
81
82## The Connect binding
83
84Inside a Prisma Compute app, AWS Lambda function, Cloudflare Worker,
85or Cloudflare Container, `Prisma.Connect` resolves the bound
86connection at runtime as a typed client:
87
88```typescript
89Effect.gen(function* () {
90 const db = yield* Prisma.Connect(connection);
91 const sql = yield* SQL.Postgres({ url: db.databaseUrl });
92
93 return {
94 fetch: Effect.gen(function* () {
95 const users = yield* sql`SELECT * FROM users`;
96 return yield* HttpServerResponse.json(users);
97 }),
98 };
99}).pipe(Effect.provide(Prisma.ConnectBinding));
100```
101
102At deploy time the binding carries the connection's outputs into the
103host's environment (env vars on Compute, Lambda, and Containers;
104secret text bindings on Workers); at runtime `db.databaseUrl` and
105friends read them back as `Redacted` values.
106
107A container is a real process with no workerd bindings, so env vars
108are its only channel — which is exactly why `Prisma.Connect` reaches
109it and `Cloudflare.Hyperdrive.Connect` does not. Start the container
110with `Cloudflare.Containers.layer(Api, { enableInternet: true })` so
111it can reach the database. See
112[Which capabilities reach a container](/cloudflare/compute/containers#which-capabilities-reach-a-container).
113
114## Rotation
115
116Change `rotate` from `false` to `true` to mint fresh credentials on
117the next deploy while keeping the connection's identity:
118
119```typescript
120const connection = yield* Prisma.Connection("api", {
121 database: postgres,
122 rotate: true,
123});
124```
125
126Prisma attempts to revoke the previous credentials on a best-effort
127basis. Downstream consumers receive the new secret on the same deploy
128through their bindings. To rotate again, deploy once with
129`rotate: false`, then change it back to `true`.
130
131## Where next
132
133- [Connect from Workers](/prisma/guides/cloudflare-workers) — both
134 wiring styles for Cloudflare, side by side.
135- [Hyperdrive](/cloudflare/data/hyperdrive) — the full pooling
136 walkthrough.
137
138Reference:
139
140- [Connection API reference](/providers/prisma/connection)