Repository navigation
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
- import
@prisma/adapter-pg - 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/@[email protected]/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine : schema-engine-cli 5a9203d0590c951969e85a7d07215503f4672eb9 (at ../../node_modules/.pnpm/@[email protected]/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"
Activity
[-]@prisma/adapter-pg modifies node-postgres global type parsers[/-][+]`@prisma/adapter-pg` modifies node-postgres global type parsers[/+]jkomyno commentedon Apr 29, 2024
Hi @matteosb, this is indeed a current side-effect of using
setTypeParserin here, as you found out. Thanks for pointing us to https://node-postgres.com/features/queries#types, we'll look into it.Also, thank you for mentioning the reasons you're using Prisma + lots of plain
node-postgres, as this allows us to understand your use case better :)Jolg42 commentedon May 30, 2024
Note: assigning myself, if someone wants to take it, go for it. Happy to pair or to pick it back another day.
fix(adapter-pg): pass customParsers to the query
Jolg42 commentedon Jun 10, 2024
@matteosb You can now try the dev version
5.16.0-dev.18This fix will be part of the official
5.16.0release scheduled for June 25th ✅matteosb commentedon Jun 10, 2024
Amazing thank you @Jolg42! I'm not sure that I will have time to test before June 25th but I'll try.