Neon
Source:
packages/better-auth/src/Neon.tsKind: Layer · Provides:BetterAuth.Database· Peer dependencies:@neondatabase/serverless
Neon database layer for Better Auth over Neon’s serverless driver.
This is the optimal Workers/Lambda → Neon pairing: the driver speaks
WebSocket instead of TCP, so it needs no Hyperdrive, no pg install,
and no socket compatibility flags. One pool per execution, closed when
the event settles.
For TCP access through Cloudflare Hyperdrive use CloudflareHyperdrive;
for a generic pg connection use Postgres.
Connecting from a Worker or Lambda
Section titled “Connecting from a Worker or Lambda”The connectionUri Output binds into the host environment at deploy
and is read back at runtime; the same source drives the deploy-time
migration Action.
import { BetterAuth } from "@alchemy.run/better-auth";import { Neon as NeonDatabase } from "@alchemy.run/better-auth/Neon";import * as Neon from "alchemy/Neon";
export const AuthDb = Neon.Project("AuthDb");
Effect.gen(function* () { const auth = yield* BetterAuth({ emailAndPassword: { enabled: true } }); return { fetch: ... };}).pipe( Effect.provide( Layer.unwrap(Effect.map(AuthDb, (db) => NeonDatabase(db.connectionUri))), ),)Branch-per-stage setups
Section titled “Branch-per-stage setups”Point the layer at a branch’s connection string instead of the project’s to isolate auth data per stage.
const branch = yield* Neon.Branch("auth-db", { project });// ...Effect.provide(Layer.unwrap(Effect.map(branch, (b) => NeonDatabase(b.connectionUri))))