@prisma/adapter-pg 6.6.0-dev.32 → 6.6.0-dev.34

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/README.md CHANGED
@@ -47,14 +47,12 @@ npm install @prisma/adapter-pg
47
47
  Finally, when you instantiate Prisma Client, you need to pass an instance of Prisma ORM's driver adapter to the `PrismaClient` constructor:
48
48
 
49
49
  ```ts
50
- import { Pool } from 'pg'
51
50
  import { PrismaPg } from '@prisma/adapter-pg'
52
51
  import { PrismaClient } from '@prisma/client'
53
52
 
54
53
  const connectionString = `${process.env.DATABASE_URL}`
55
54
 
56
- const pool = new Pool({ connectionString })
57
- const adapter = new PrismaPg(pool)
55
+ const adapter = new PrismaPg({ connectionString })
58
56
  const prisma = new PrismaClient({ adapter })
59
57
  ```
60
58
 
package/dist/index.d.mts CHANGED
@@ -1,51 +1,19 @@
1
- import type { ConnectionInfo } from '@prisma/driver-adapter-utils';
2
1
  import pg from 'pg';
3
- import type { SqlConnection } from '@prisma/driver-adapter-utils';
4
- import type { SqlQuery } from '@prisma/driver-adapter-utils';
5
- import type { SqlQueryable } from '@prisma/driver-adapter-utils';
6
- import type { SqlResultSet } from '@prisma/driver-adapter-utils';
7
- import type { TransactionContext } from '@prisma/driver-adapter-utils';
2
+ import type { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
3
+ import type { SqlMigrationAwareDriverAdapterFactory } from '@prisma/driver-adapter-utils';
8
4
 
9
- declare class PgQueryable<ClientT extends StdClient | TransactionClient> implements SqlQueryable {
10
- protected readonly client: ClientT;
5
+ export declare class PrismaPg implements SqlMigrationAwareDriverAdapterFactory {
6
+ private readonly config;
7
+ private readonly options?;
11
8
  readonly provider = "postgres";
12
9
  readonly adapterName: string;
13
- constructor(client: ClientT);
14
- /**
15
- * Execute a query given as SQL, interpolating the given parameters.
16
- */
17
- queryRaw(query: SqlQuery): Promise<SqlResultSet>;
18
- /**
19
- * Execute a query given as SQL, interpolating the given parameters and
20
- * returning the number of affected rows.
21
- * Note: Queryable expects a u64, but napi.rs only supports u32.
22
- */
23
- executeRaw(query: SqlQuery): Promise<number>;
24
- /**
25
- * Run a query against the database, returning the result set.
26
- * Should the query fail due to a connection error, the connection is
27
- * marked as unhealthy.
28
- */
29
- private performIO;
30
- protected onError(error: any): never;
31
- }
32
-
33
- export declare class PrismaPg extends PgQueryable<StdClient> implements SqlConnection {
34
- private options?;
35
- private readonly release?;
36
- constructor(client: StdClient, options?: PrismaPgOptions | undefined, release?: (() => Promise<void>) | undefined);
37
- executeScript(script: string): Promise<void>;
38
- getConnectionInfo(): ConnectionInfo;
39
- transactionContext(): Promise<TransactionContext>;
40
- dispose(): Promise<void>;
10
+ constructor(config: pg.PoolConfig, options?: PrismaPgOptions | undefined);
11
+ connect(): Promise<SqlDriverAdapter>;
12
+ connectToShadowDb(): Promise<SqlDriverAdapter>;
41
13
  }
42
14
 
43
15
  declare type PrismaPgOptions = {
44
16
  schema?: string;
45
17
  };
46
18
 
47
- declare type StdClient = pg.Pool;
48
-
49
- declare type TransactionClient = pg.PoolClient;
50
-
51
19
  export { }
package/dist/index.d.ts CHANGED
@@ -1,51 +1,19 @@
1
- import type { ConnectionInfo } from '@prisma/driver-adapter-utils';
2
1
  import pg from 'pg';
3
- import type { SqlConnection } from '@prisma/driver-adapter-utils';
4
- import type { SqlQuery } from '@prisma/driver-adapter-utils';
5
- import type { SqlQueryable } from '@prisma/driver-adapter-utils';
6
- import type { SqlResultSet } from '@prisma/driver-adapter-utils';
7
- import type { TransactionContext } from '@prisma/driver-adapter-utils';
2
+ import type { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
3
+ import type { SqlMigrationAwareDriverAdapterFactory } from '@prisma/driver-adapter-utils';
8
4
 
9
- declare class PgQueryable<ClientT extends StdClient | TransactionClient> implements SqlQueryable {
10
- protected readonly client: ClientT;
5
+ export declare class PrismaPg implements SqlMigrationAwareDriverAdapterFactory {
6
+ private readonly config;
7
+ private readonly options?;
11
8
  readonly provider = "postgres";
12
9
  readonly adapterName: string;
13
- constructor(client: ClientT);
14
- /**
15
- * Execute a query given as SQL, interpolating the given parameters.
16
- */
17
- queryRaw(query: SqlQuery): Promise<SqlResultSet>;
18
- /**
19
- * Execute a query given as SQL, interpolating the given parameters and
20
- * returning the number of affected rows.
21
- * Note: Queryable expects a u64, but napi.rs only supports u32.
22
- */
23
- executeRaw(query: SqlQuery): Promise<number>;
24
- /**
25
- * Run a query against the database, returning the result set.
26
- * Should the query fail due to a connection error, the connection is
27
- * marked as unhealthy.
28
- */
29
- private performIO;
30
- protected onError(error: any): never;
31
- }
32
-
33
- export declare class PrismaPg extends PgQueryable<StdClient> implements SqlConnection {
34
- private options?;
35
- private readonly release?;
36
- constructor(client: StdClient, options?: PrismaPgOptions | undefined, release?: (() => Promise<void>) | undefined);
37
- executeScript(script: string): Promise<void>;
38
- getConnectionInfo(): ConnectionInfo;
39
- transactionContext(): Promise<TransactionContext>;
40
- dispose(): Promise<void>;
10
+ constructor(config: pg.PoolConfig, options?: PrismaPgOptions | undefined);
11
+ connect(): Promise<SqlDriverAdapter>;
12
+ connectToShadowDb(): Promise<SqlDriverAdapter>;
41
13
  }
42
14
 
43
15
  declare type PrismaPgOptions = {
44
16
  schema?: string;
45
17
  };
46
18
 
47
- declare type StdClient = pg.Pool;
48
-
49
- declare type TransactionClient = pg.PoolClient;
50
-
51
19
  export { }
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- PrismaPg: () => PrismaPg
33
+ PrismaPg: () => PrismaPgAdapterFactory
34
34
  });
35
35
  module.exports = __toCommonJS(index_exports);
36
36
 
@@ -484,32 +484,34 @@ var PgTransaction = class extends PgQueryable {
484
484
  this.client.release();
485
485
  }
486
486
  };
487
- var PgTransactionContext = class extends PgQueryable {
488
- constructor(conn) {
489
- super(conn);
490
- this.conn = conn;
487
+ var PrismaPgAdapter = class extends PgQueryable {
488
+ constructor(client, options, release) {
489
+ super(client);
490
+ this.options = options;
491
+ this.release = release;
491
492
  }
492
- async startTransaction() {
493
+ async startTransaction(isolationLevel) {
493
494
  const options = {
494
495
  usePhantomQuery: false
495
496
  };
496
497
  const tag = "[js::startTransaction]";
497
498
  debug("%s options: %O", tag, options);
498
- return new PgTransaction(this.conn, options);
499
- }
500
- };
501
- var PrismaPg = class extends PgQueryable {
502
- constructor(client, options, release) {
503
- if (!client) {
504
- throw new TypeError(`PrismaPg must be initialized with an instance of Pool:
505
- import { Pool } from 'pg'
506
- const pool = new Pool({ connectionString: url })
507
- const adapter = new PrismaPg(pool)
508
- `);
499
+ const conn = await this.client.connect();
500
+ const tx = new PgTransaction(conn, options);
501
+ try {
502
+ await tx.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
503
+ if (isolationLevel) {
504
+ await tx.executeRaw({
505
+ sql: `SET TRANSACTION ISOLATION LEVEL ${isolationLevel}`,
506
+ args: [],
507
+ argTypes: []
508
+ });
509
+ }
510
+ return tx;
511
+ } catch (error) {
512
+ conn.release(error);
513
+ throw error;
509
514
  }
510
- super(client);
511
- this.options = options;
512
- this.release = release;
513
515
  }
514
516
  async executeScript(script) {
515
517
  for (const stmt of script.split(";")) {
@@ -525,15 +527,32 @@ const adapter = new PrismaPg(pool)
525
527
  schemaName: this.options?.schema
526
528
  };
527
529
  }
528
- async transactionContext() {
529
- const conn = await this.client.connect();
530
- return new PgTransactionContext(conn);
531
- }
532
530
  async dispose() {
533
531
  await this.release?.();
534
532
  return await this.client.end();
535
533
  }
536
534
  };
535
+ var PrismaPgAdapterFactory = class {
536
+ constructor(config, options) {
537
+ this.config = config;
538
+ this.options = options;
539
+ }
540
+ provider = "postgres";
541
+ adapterName = name;
542
+ async connect() {
543
+ return new PrismaPgAdapter(new import_pg2.default.Pool(this.config), this.options, async () => {
544
+ });
545
+ }
546
+ async connectToShadowDb() {
547
+ const conn = await this.connect();
548
+ const database = `prisma_migrate_shadow_db_${globalThis.crypto.randomUUID()}`;
549
+ await conn.executeScript(`CREATE DATABASE "${database}"`);
550
+ return new PrismaPgAdapter(new import_pg2.default.Pool({ ...this.config, database }), void 0, async () => {
551
+ await conn.executeScript(`DROP DATABASE "${database}"`);
552
+ await conn.dispose();
553
+ });
554
+ }
555
+ };
537
556
  // Annotate the CommonJS export names for ESM import in node:
538
557
  0 && (module.exports = {
539
558
  PrismaPg
package/dist/index.mjs CHANGED
@@ -448,32 +448,34 @@ var PgTransaction = class extends PgQueryable {
448
448
  this.client.release();
449
449
  }
450
450
  };
451
- var PgTransactionContext = class extends PgQueryable {
452
- constructor(conn) {
453
- super(conn);
454
- this.conn = conn;
451
+ var PrismaPgAdapter = class extends PgQueryable {
452
+ constructor(client, options, release) {
453
+ super(client);
454
+ this.options = options;
455
+ this.release = release;
455
456
  }
456
- async startTransaction() {
457
+ async startTransaction(isolationLevel) {
457
458
  const options = {
458
459
  usePhantomQuery: false
459
460
  };
460
461
  const tag = "[js::startTransaction]";
461
462
  debug("%s options: %O", tag, options);
462
- return new PgTransaction(this.conn, options);
463
- }
464
- };
465
- var PrismaPg = class extends PgQueryable {
466
- constructor(client, options, release) {
467
- if (!client) {
468
- throw new TypeError(`PrismaPg must be initialized with an instance of Pool:
469
- import { Pool } from 'pg'
470
- const pool = new Pool({ connectionString: url })
471
- const adapter = new PrismaPg(pool)
472
- `);
463
+ const conn = await this.client.connect();
464
+ const tx = new PgTransaction(conn, options);
465
+ try {
466
+ await tx.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
467
+ if (isolationLevel) {
468
+ await tx.executeRaw({
469
+ sql: `SET TRANSACTION ISOLATION LEVEL ${isolationLevel}`,
470
+ args: [],
471
+ argTypes: []
472
+ });
473
+ }
474
+ return tx;
475
+ } catch (error) {
476
+ conn.release(error);
477
+ throw error;
473
478
  }
474
- super(client);
475
- this.options = options;
476
- this.release = release;
477
479
  }
478
480
  async executeScript(script) {
479
481
  for (const stmt of script.split(";")) {
@@ -489,15 +491,32 @@ const adapter = new PrismaPg(pool)
489
491
  schemaName: this.options?.schema
490
492
  };
491
493
  }
492
- async transactionContext() {
493
- const conn = await this.client.connect();
494
- return new PgTransactionContext(conn);
495
- }
496
494
  async dispose() {
497
495
  await this.release?.();
498
496
  return await this.client.end();
499
497
  }
500
498
  };
499
+ var PrismaPgAdapterFactory = class {
500
+ constructor(config, options) {
501
+ this.config = config;
502
+ this.options = options;
503
+ }
504
+ provider = "postgres";
505
+ adapterName = name;
506
+ async connect() {
507
+ return new PrismaPgAdapter(new pg2.Pool(this.config), this.options, async () => {
508
+ });
509
+ }
510
+ async connectToShadowDb() {
511
+ const conn = await this.connect();
512
+ const database = `prisma_migrate_shadow_db_${globalThis.crypto.randomUUID()}`;
513
+ await conn.executeScript(`CREATE DATABASE "${database}"`);
514
+ return new PrismaPgAdapter(new pg2.Pool({ ...this.config, database }), void 0, async () => {
515
+ await conn.executeScript(`DROP DATABASE "${database}"`);
516
+ await conn.dispose();
517
+ });
518
+ }
519
+ };
501
520
  export {
502
- PrismaPg
521
+ PrismaPgAdapterFactory as PrismaPg
503
522
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-pg",
3
- "version": "6.6.0-dev.32",
3
+ "version": "6.6.0-dev.34",
4
4
  "description": "Prisma's driver adapter for \"pg\"",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -32,7 +32,7 @@
32
32
  "sideEffects": false,
33
33
  "dependencies": {
34
34
  "postgres-array": "3.0.4",
35
- "@prisma/driver-adapter-utils": "6.6.0-dev.32"
35
+ "@prisma/driver-adapter-utils": "6.6.0-dev.34"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@swc/core": "1.11.5",