Skip to content

@prisma/adapter-pg modifies node-postgres global type parsers #23505

Closed
@matteosb

Description

Bug description

Using the Prisma node-postgres adapter breaks queries run directly through node-postgres Pool and Client instances, even when the instance of Pool is not shared with the Prisma adapter. This is a problem for us because we'd like to use Prisma with the adapter, but we use node-postgres extensively, including for use-cases that Prisma doesn't support (streaming in particular).

Fortunately I think this should be very easy to fix: @prisma/adapter-pg registers its type parsers globally here. It could instead pass the type parsers to its queries explictly as described here.

How to reproduce

  1. import @prisma/adapter-pg
  2. Run a query via node-postgres

This script illustrates the problem with timestamp parsing and doesn't require a Prisma schema:

import { Pool } from "pg";

const pgPool = new Pool({ connectionString: process.env.DATABASE_URL });

async function main() {
  const before = await pgPool.query(`SELECT NOW() as ts`);
  console.log(
    "NOW() before @prisma/adapter-pg - value:",
    before.rows[0].ts,
    "type:",
    typeof before.rows[0].ts
  );

  require("@prisma/adapter-pg");

  const after = await pgPool.query(`SELECT NOW() as ts`);
  console.log(
    "NOW() after @prisma/adapter-pg - value:",
    after.rows[0].ts,
    "type:",
    typeof after.rows[0].ts
  );
}

main().finally(() => pgPool.end());

output:

NOW() before @prisma/adapter-pg - value: 2024-03-15T15:48:47.231Z type: object
NOW() after @prisma/adapter-pg - value: 2024-03-15 15:48:47.237668 type: string

Expected behavior

@prisma/adapter-pg shouldn't modify node-postgres's global type parsers. Instead, performIO could pass Prisma's custom type parsers as described in the node-postgres documentation.

Prisma information

This can be reproduced without any Prisma schema

Environment & setup

  • OS: tested on macOS and Debian
  • Database: PostgreSQL
  • Node.js version: 20.11.0

Prisma Version

prisma                  : 5.10.2
@prisma/client          : 5.10.2
Computed binaryTarget   : darwin-arm64
Operating System        : darwin
Architecture            : arm64
Node.js                 : v20.11.0
Query Engine (Node-API) : libquery-engine 5a9203d0590c951969e85a7d07215503f4672eb9 (at ../../node_modules/.pnpm/@prisma+engines@5.10.2/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine           : schema-engine-cli 5a9203d0590c951969e85a7d07215503f4672eb9 (at ../../node_modules/.pnpm/@prisma+engines@5.10.2/node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm             : @prisma/prisma-schema-wasm 5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9
Default Engines Hash    : 5a9203d0590c951969e85a7d07215503f4672eb9
Studio                  : 0.499.0
Preview Features        : driverAdapters, metrics, views
"@prisma/adapter-pg": "^5.11.0"

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions