Skip to content

Commit a086f59

Browse files
authored
Fixed pg-native Pool detection in node-postgres transactions breaking in environments with forbidden require() (fixes #5107) (#5118)
1 parent c445637 commit a086f59

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

changelogs/drizzle-orm/0.45.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixed pg-native Pool detection in node-postgres transactions breaking in environments with forbidden `require()` ([#5107](https://github.com/drizzle-team/drizzle-orm/issues/5107))

drizzle-orm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-orm",
3-
"version": "0.45.0",
3+
"version": "0.45.1",
44
"description": "Drizzle ORM package for SQL databases",
55
"type": "module",
66
"scripts": {

drizzle-orm/src/node-postgres/session.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { tracer } from '~/tracing.ts';
1515
import { type Assume, mapResultRow } from '~/utils.ts';
1616

1717
const { Pool, types } = pg;
18-
const NativePool = (<any> pg).native ? (<{ Pool: typeof Pool }> (<any> pg).native).Pool : undefined;
1918

2019
export type NodePgClient = pg.Pool | PoolClient | Client;
2120

@@ -250,8 +249,9 @@ export class NodePgSession<
250249
transaction: (tx: NodePgTransaction<TFullSchema, TSchema>) => Promise<T>,
251250
config?: PgTransactionConfig | undefined,
252251
): Promise<T> {
253-
const session = (this.client instanceof Pool || (NativePool && this.client instanceof NativePool)) // eslint-disable-line no-instanceof/no-instanceof
254-
? new NodePgSession(await this.client.connect(), this.dialect, this.schema, this.options)
252+
const isPool = this.client instanceof Pool || Object.getPrototypeOf(this.client).constructor.name.includes('Pool'); // eslint-disable-line no-instanceof/no-instanceof
253+
const session = isPool
254+
? new NodePgSession(await (<pg.Pool> this.client).connect(), this.dialect, this.schema, this.options)
255255
: this;
256256
const tx = new NodePgTransaction<TFullSchema, TSchema>(this.dialect, session, this.schema);
257257
await tx.execute(sql`begin${config ? sql` ${tx.getTransactionConfigSQL(config)}` : undefined}`);
@@ -263,9 +263,7 @@ export class NodePgSession<
263263
await tx.execute(sql`rollback`);
264264
throw error;
265265
} finally {
266-
if (this.client instanceof Pool || (NativePool && this.client instanceof NativePool)) { // eslint-disable-line no-instanceof/no-instanceof
267-
(session.client as PoolClient).release();
268-
}
266+
if (isPool) (session.client as PoolClient).release();
269267
}
270268
}
271269

0 commit comments

Comments
 (0)