Skip to content

feat(drizzle): expose vanilla node-postgres client on Drizzle.postgres#280

Open
anaydot wants to merge 2 commits into
alchemy-run:mainfrom
anaydot:feat/drizzle-postgres-raw
Open

feat(drizzle): expose vanilla node-postgres client on Drizzle.postgres#280
anaydot wants to merge 2 commits into
alchemy-run:mainfrom
anaydot:feat/drizzle-postgres-raw

Conversation

@anaydot
Copy link
Copy Markdown

@anaydot anaydot commented May 8, 2026

Refs #274 — building block for a BetterAuth.DrizzlePostgres layer (separate PR).

Adds Drizzle.postgresRaw(...) — a vanilla drizzle-orm/node-postgres client for libraries that need a regular promise-shaped drizzle (e.g. better-auth's drizzleAdapter).

const raw = yield* Drizzle.postgresRaw(hd.connectionString);

const auth = betterAuth({
  database: drizzleAdapter(raw, { provider: "pg", schema }),
});

Lives in its own module so apps using only the Effect-flavored Drizzle.postgres don't pull drizzle-orm/node-postgres into the bundle. The drizzle client is cached per-ExecutionContext — the pool is built at most once per request.

@anaydot anaydot marked this pull request as ready for review May 8, 2026 03:16
Adds `db.raw` to the object returned by `Drizzle.postgres(...)`. It
yields a vanilla `drizzle-orm/node-postgres` instance backed by the
same connection string. Use it for libraries that need a regular
promise-shaped drizzle (e.g. better-auth's `drizzleAdapter`):

```ts
const db = yield* Drizzle.postgres(hd.connectionString);
const raw = yield* db.raw;

const auth = betterAuth({
  database: drizzleAdapter(raw, { provider: "pg", schema }),
});
```

The drizzle client is cached per-`ExecutionContext` so the pool is
built at most once per request.
@anaydot anaydot force-pushed the feat/drizzle-postgres-raw branch from 309ec1e to f8b5929 Compare May 8, 2026 07:54
Comment on lines +107 to +115
return new Proxy(effectDb as any, {
get(target, prop, receiver) {
if (prop === "raw") return raw;
return Reflect.get(target, prop, receiver);
},
}) as EffectPgDatabase<TRelations> & {
$client: PgClient.PgClient;
raw: Effect.Effect<NodePgDatabase<TRelations>, E, R | ExecutionContext>;
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it not using proxyChain helper anymore?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restructured — .raw moved out of Drizzle.postgres entirely and into a new Drizzle.postgresRaw export, per the tree-shaking feedback on #281 (comment).

@anaydot anaydot requested a review from sam-goodwin May 11, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants