Skip to content

Postgres

Source: packages/better-auth/src/Postgres.ts Kind: Layer · Provides: BetterAuth.Database · Peer dependencies: pg

Generic TCP Postgres database layer for Better Auth, from a connection string.

Works with every Postgres alchemy exposes a connection string for: PlanetScale Postgres (role.connectionUrl), Prisma Postgres (connection.databaseUrl), AWS RDS inside a VPC, or any literal URL. One pg.Pool is opened per execution and closed when the event settles — the only legal pooling shape on workerd. Prefer Neon, AuroraDataApi, or CloudflareHyperdrive when they match your environment → database pair.

On AWS Lambda, add build: { install: ["pg"] } to the Function props so the dynamically-imported driver ships in the artifact with an npm layout (its CJS require chain does not survive store-style node_modules).

Resource Outputs are bound into the host environment at deploy and read back at runtime; the same source drives deploy-time migrations.

import { BetterAuth } from "@alchemy.run/better-auth";
import { Postgres } from "@alchemy.run/better-auth/Postgres";
const role = yield* Planetscale.PostgresRole("auth-role", { database, branch });
Effect.gen(function* () {
const auth = yield* BetterAuth({ emailAndPassword: { enabled: true } });
return { fetch: ... };
}).pipe(Effect.provide(Postgres(role.connectionUrl)))

When the runtime URL is not deploy-resolvable (or points at a pooler), pass a direct deploy-time URL as migrate.

Postgres(role.connectionUrlPooled, { migrate: role.connectionUrl })