@@ -15,7 +15,6 @@ import { tracer } from '~/tracing.ts';
1515import { type Assume , mapResultRow } from '~/utils.ts' ;
1616
1717const { Pool, types } = pg ;
18- const NativePool = ( < any > pg ) . native ? ( < { Pool : typeof Pool } > ( < any > pg ) . native ) . Pool : undefined ;
1918
2019export 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