@prisma/adapter-pg 6.13.0-dev.1 → 6.13.0-dev.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -3,17 +3,19 @@ import type { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
3
3
  import type { SqlMigrationAwareDriverAdapterFactory } from '@prisma/driver-adapter-utils';
4
4
 
5
5
  export declare class PrismaPg implements SqlMigrationAwareDriverAdapterFactory {
6
- private readonly config;
7
6
  private readonly options?;
8
7
  readonly provider = "postgres";
9
8
  readonly adapterName: string;
10
- constructor(config: pg.PoolConfig, options?: PrismaPgOptions | undefined);
9
+ private readonly config;
10
+ private externalPool;
11
+ constructor(poolOrConfig: pg.Pool | pg.PoolConfig, options?: PrismaPgOptions | undefined);
11
12
  connect(): Promise<SqlDriverAdapter>;
12
13
  connectToShadowDb(): Promise<SqlDriverAdapter>;
13
14
  }
14
15
 
15
16
  declare type PrismaPgOptions = {
16
17
  schema?: string;
18
+ disposeExternalPool?: boolean;
17
19
  };
18
20
 
19
21
  export { }
package/dist/index.d.ts CHANGED
@@ -3,17 +3,19 @@ import type { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
3
3
  import type { SqlMigrationAwareDriverAdapterFactory } from '@prisma/driver-adapter-utils';
4
4
 
5
5
  export declare class PrismaPg implements SqlMigrationAwareDriverAdapterFactory {
6
- private readonly config;
7
6
  private readonly options?;
8
7
  readonly provider = "postgres";
9
8
  readonly adapterName: string;
10
- constructor(config: pg.PoolConfig, options?: PrismaPgOptions | undefined);
9
+ private readonly config;
10
+ private externalPool;
11
+ constructor(poolOrConfig: pg.Pool | pg.PoolConfig, options?: PrismaPgOptions | undefined);
11
12
  connect(): Promise<SqlDriverAdapter>;
12
13
  connectToShadowDb(): Promise<SqlDriverAdapter>;
13
14
  }
14
15
 
15
16
  declare type PrismaPgOptions = {
16
17
  schema?: string;
18
+ disposeExternalPool?: boolean;
17
19
  };
18
20
 
19
21
  export { }
package/dist/index.js CHANGED
@@ -620,27 +620,45 @@ var PrismaPgAdapter = class extends PgQueryable {
620
620
  };
621
621
  }
622
622
  async dispose() {
623
- await this.release?.();
624
- return await this.client.end();
623
+ return this.release?.();
625
624
  }
626
625
  };
627
626
  var PrismaPgAdapterFactory = class {
628
- constructor(config, options) {
629
- this.config = config;
627
+ constructor(poolOrConfig, options) {
630
628
  this.options = options;
629
+ if (poolOrConfig instanceof import_pg2.default.Pool) {
630
+ this.externalPool = poolOrConfig;
631
+ this.config = poolOrConfig.options;
632
+ } else {
633
+ this.externalPool = null;
634
+ this.config = poolOrConfig;
635
+ }
631
636
  }
632
637
  provider = "postgres";
633
638
  adapterName = name;
639
+ config;
640
+ externalPool;
634
641
  async connect() {
635
- return new PrismaPgAdapter(new import_pg2.default.Pool(this.config), this.options, async () => {
642
+ const client = this.externalPool ?? new import_pg2.default.Pool(this.config);
643
+ return new PrismaPgAdapter(client, this.options, async () => {
644
+ if (this.externalPool) {
645
+ if (this.options?.disposeExternalPool) {
646
+ await this.externalPool.end();
647
+ this.externalPool = null;
648
+ }
649
+ } else {
650
+ await client.end();
651
+ }
636
652
  });
637
653
  }
638
654
  async connectToShadowDb() {
639
655
  const conn = await this.connect();
640
656
  const database = `prisma_migrate_shadow_db_${globalThis.crypto.randomUUID()}`;
641
657
  await conn.executeScript(`CREATE DATABASE "${database}"`);
642
- return new PrismaPgAdapter(new import_pg2.default.Pool({ ...this.config, database }), void 0, async () => {
658
+ const client = new import_pg2.default.Pool({ ...this.config, database });
659
+ return new PrismaPgAdapter(client, void 0, async () => {
643
660
  await conn.executeScript(`DROP DATABASE "${database}"`);
661
+ await client.end();
644
662
  });
645
663
  }
646
664
  };
package/dist/index.mjs CHANGED
@@ -584,27 +584,45 @@ var PrismaPgAdapter = class extends PgQueryable {
584
584
  };
585
585
  }
586
586
  async dispose() {
587
- await this.release?.();
588
- return await this.client.end();
587
+ return this.release?.();
589
588
  }
590
589
  };
591
590
  var PrismaPgAdapterFactory = class {
592
- constructor(config, options) {
593
- this.config = config;
591
+ constructor(poolOrConfig, options) {
594
592
  this.options = options;
593
+ if (poolOrConfig instanceof pg2.Pool) {
594
+ this.externalPool = poolOrConfig;
595
+ this.config = poolOrConfig.options;
596
+ } else {
597
+ this.externalPool = null;
598
+ this.config = poolOrConfig;
599
+ }
595
600
  }
596
601
  provider = "postgres";
597
602
  adapterName = name;
603
+ config;
604
+ externalPool;
598
605
  async connect() {
599
- return new PrismaPgAdapter(new pg2.Pool(this.config), this.options, async () => {
606
+ const client = this.externalPool ?? new pg2.Pool(this.config);
607
+ return new PrismaPgAdapter(client, this.options, async () => {
608
+ if (this.externalPool) {
609
+ if (this.options?.disposeExternalPool) {
610
+ await this.externalPool.end();
611
+ this.externalPool = null;
612
+ }
613
+ } else {
614
+ await client.end();
615
+ }
600
616
  });
601
617
  }
602
618
  async connectToShadowDb() {
603
619
  const conn = await this.connect();
604
620
  const database = `prisma_migrate_shadow_db_${globalThis.crypto.randomUUID()}`;
605
621
  await conn.executeScript(`CREATE DATABASE "${database}"`);
606
- return new PrismaPgAdapter(new pg2.Pool({ ...this.config, database }), void 0, async () => {
622
+ const client = new pg2.Pool({ ...this.config, database });
623
+ return new PrismaPgAdapter(client, void 0, async () => {
607
624
  await conn.executeScript(`DROP DATABASE "${database}"`);
625
+ await client.end();
608
626
  });
609
627
  }
610
628
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-pg",
3
- "version": "6.13.0-dev.1",
3
+ "version": "6.13.0-dev.10",
4
4
  "description": "Prisma's driver adapter for \"pg\"",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -33,7 +33,7 @@
33
33
  "dependencies": {
34
34
  "postgres-array": "3.0.4",
35
35
  "pg": "^8.11.3",
36
- "@prisma/driver-adapter-utils": "6.13.0-dev.1"
36
+ "@prisma/driver-adapter-utils": "6.13.0-dev.10"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@swc/core": "1.11.5",