Skip to content

Support custom pg-compatible Pool implementations in @prisma/adapter-pg (e.g. YugabyteDB smart driver) #29897

Open

Description

@HossamSayed8858

What problem are you trying to solve?

@prisma/adapter-pg currently type-checks and validates the pool passed into PrismaPg against its own bundled pg.Pool class (type StdClient = pg.Pool in pg.ts). This means any drop-in-compatible fork of pg — for example YugabyteDB's smart driver (@yugabytedb/pg), which extends pg to add cluster-topology-aware load balancing and failover — fails to work with Prisma, even though it implements the same interface and is designed as a compatible replacement.

Problem:
Other ORMs (TypeORM, Sequelize, Drizzle) support these forks transparently via simple package aliasing ("pg": "npm:@yugabytedb/pg" in package.json), because they consume pg structurally rather than checking identity against a specific bundled class. @prisma/adapter-pg cannot do this today because it depends on its own internal copy of pg, and its Pool validation is tied to that exact class reference.

Impact:
Without this, Prisma users on distributed Postgres-compatible databases like YugabyteDB (or CockroachDB, or any future fork with similar smart-driver patterns) can't get automatic node-discovery/failover from the driver layer. The only workaround is standing up an external load balancer (e.g. HAProxy) in front of the cluster, purely to compensate for something the driver could otherwise do natively.

Request:
Could @prisma/adapter-pg validate the passed pool structurally (duck-typing against the required methods: .query(), .connect(), .end(), etc.) instead of via instanceof against its own bundled pg.Pool? This would let compatible forks work without requiring Prisma to explicitly support each one.

Happy to provide a minimal repro if useful.

Proposed solution

Proposed solution

Instead of relying on instanceof pg.Pool (which only matches the exact bundled class), validate the passed object structurally — check that it exposes the methods @prisma/adapter-pg actually uses (query, connect, end, and whatever else the adapter calls internally), similar to duck-typing:

function isPgPoolLike(obj: unknown): obj is StdClient {
return (
!!obj &&
typeof (obj as any).query === 'function' &&
typeof (obj as any).connect === 'function' &&
typeof (obj as any).end === 'function'
);
}

This would accept any object that behaves like a pg.Pool — including forks such as @yugabytedb/pg's BoundPool — without Prisma needing to explicitly special-case each fork.

Alternative, if a structural check is considered too loose: expose an explicit escape hatch, e.g. an unsafeSkipPoolValidation (or similarly named) constructor option on PrismaPg, so users who know they're passing a compatible fork can opt in without Prisma having to guarantee full type safety for every possible pg-compatible driver:

const adapter = new PrismaPg(customPool, { unsafeSkipPoolValidation: true })

Either approach unblocks compatible forks (YugabyteDB smart driver, and potentially others in the future) without requiring Prisma to take on a maintenance burden for each one individually. I'd lean toward the structural check as the cleaner long-term fix, with the escape hatch as a lower-effort stopgap if that's easier to ship first.

Alternatives considered

No response

Scope and impact

No response

Activity

  1. SnowingFox commented on Aug 10, 2026

    @SnowingFox

    Opened a PR to address this: #29956

  2. added 2 commits that reference this issue on Aug 11, 2026
    98c73ea
    6972e7c
  3. Mohamed-Sayed-M commented on Oct 2, 2026

    @Mohamed-Sayed-M

    when it will be closed ? i run this issue also . i can see someone has solution but why it did not merge ?

  4. Mohamed-Sayed-M commented on Oct 2, 2026

    @Mohamed-Sayed-M

    does the prisma 8 fix this ?

  5. added a commit that references this issue on Oct 24, 2026
    56767f4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions