Skip to content

Prisma.Postgres reference

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.

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.)

Source: src/Prisma/Connection.ts

A Prisma database connection/API key.

Prisma returns connection credentials only when it creates or rotates a connection. Alchemy stores those outputs as Redacted values. Changing the database or name replaces the connection; changing rotate from false to true keeps the connection ID and requests fresh credentials.

const connection = yield* Prisma.Connection("api", {
database: database.databaseId,
});

Pass database URLs to Compute env

const connection = yield* Prisma.Connection("api", {
database,
});
const app = yield* Prisma.Compute("api", {
project,
path: "./apps/api",
env: {
DATABASE_URL: connection.databaseUrl,
DIRECT_URL: connection.directConnectionString,
},
});

Use a connection inside an Effect-native Compute app

export default Prisma.Compute(
"api",
{ project, appName: "api", 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 an Effect-native Lambda function

export default AWS.Lambda.Function(
"api",
{ main: import.meta.filename, functionUrl: true },
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 an Effect-native Cloudflare Worker

export default Cloudflare.Worker(
"api",
{ main: import.meta.filename, compatibility: { flags: ["nodejs_compat"] } },
Effect.gen(function* () {
const db = yield* Prisma.Connect(connection);
const sql = yield* SQL.Postgres({ url: db.databaseUrl });
return {
fetch: Effect.gen(function* () {
const result = yield* sql`SELECT 1 AS ok`;
return yield* HttpServerResponse.json(result);
}),
};
}).pipe(Effect.provide(Prisma.ConnectBinding)),
);
const connection = yield* Prisma.Connection("api", {
database,
rotate: true,
});
const hyperdrive = yield* Cloudflare.Hyperdrive.Connection("api-hd", {
origin: connection.origin.as<Prisma.PostgresOrigin>(),
});
export default Cloudflare.Worker(
"api",
{ main: import.meta.filename, compatibility: { flags: ["nodejs_compat"] } },
Effect.gen(function* () {
const hd = yield* Cloudflare.Hyperdrive.Connect(hyperdrive);
const sql = yield* SQL.Postgres({ url: hd.connectionString });
return {
fetch: Effect.gen(function* () {
const users = yield* sql`SELECT * FROM users`;
return yield* HttpServerResponse.json(users);
}),
};
}).pipe(Effect.provide(Cloudflare.Hyperdrive.ConnectBinding)),
);

Source: src/Prisma/Database.ts

A Prisma Postgres database inside a Prisma project.

Standalone Prisma.Database resources cannot be the project’s default database. Use Prisma.Project when the project should own a default database. Project, region, and source changes require replacement; display name and branch attachment can converge in place. Destroying this resource deletes its database and data.

Database in a project

const project = yield* Prisma.Project("app", { createDatabase: false });
const database = yield* Prisma.Database("db", {
project,
region: "us-east-1",
});

Database attached to a preview branch

const database = yield* Prisma.Database("preview-db", {
project,
branchId: preview.branchId,
});

Source: src/Prisma/Postgres.ts

Product-shaped convenience alias for Database.

Prisma.Postgres(...) and Prisma.Database(...) use the same underlying Prisma Postgres resource provider. Prefer Postgres when you want the code to read like the Prisma product name, and Database when you want to mirror the Management API route names. Like Database, this standalone resource cannot be the project’s default database; use Prisma.Project to own the default.

const project = yield* Prisma.Project("app", { createDatabase: false });
const postgres = yield* Prisma.Postgres("db", {
project,
region: "us-east-1",
});