@prisma/adapter-pg 6.5.0-integration-fix-e2e-prisma-config-2.9 → 6.5.0-integration-fix-client-read-replicas.2

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
@@ -1,13 +1,12 @@
1
1
  import type { ConnectionInfo } from '@prisma/driver-adapter-utils';
2
- import type { DriverAdapter } from '@prisma/driver-adapter-utils';
3
2
  import pg from 'pg';
4
- import type { Query } from '@prisma/driver-adapter-utils';
5
- import type { Queryable } from '@prisma/driver-adapter-utils';
6
- import type { Result } from '@prisma/driver-adapter-utils';
7
- import type { ResultSet } from '@prisma/driver-adapter-utils';
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';
8
7
  import type { TransactionContext } from '@prisma/driver-adapter-utils';
9
8
 
10
- declare class PgQueryable<ClientT extends StdClient | TransactionClient> implements Queryable {
9
+ declare class PgQueryable<ClientT extends StdClient | TransactionClient> implements SqlQueryable {
11
10
  protected readonly client: ClientT;
12
11
  readonly provider = "postgres";
13
12
  readonly adapterName: string;
@@ -15,26 +14,30 @@ declare class PgQueryable<ClientT extends StdClient | TransactionClient> impleme
15
14
  /**
16
15
  * Execute a query given as SQL, interpolating the given parameters.
17
16
  */
18
- queryRaw(query: Query): Promise<Result<ResultSet>>;
17
+ queryRaw(query: SqlQuery): Promise<SqlResultSet>;
19
18
  /**
20
19
  * Execute a query given as SQL, interpolating the given parameters and
21
20
  * returning the number of affected rows.
22
21
  * Note: Queryable expects a u64, but napi.rs only supports u32.
23
22
  */
24
- executeRaw(query: Query): Promise<Result<number>>;
23
+ executeRaw(query: SqlQuery): Promise<number>;
25
24
  /**
26
25
  * Run a query against the database, returning the result set.
27
26
  * Should the query fail due to a connection error, the connection is
28
27
  * marked as unhealthy.
29
28
  */
30
29
  private performIO;
30
+ protected onError(error: any): never;
31
31
  }
32
32
 
33
- export declare class PrismaPg extends PgQueryable<StdClient> implements DriverAdapter {
33
+ export declare class PrismaPg extends PgQueryable<StdClient> implements SqlConnection {
34
34
  private options?;
35
- constructor(client: pg.Pool, options?: PrismaPgOptions | undefined);
36
- getConnectionInfo(): Result<ConnectionInfo>;
37
- transactionContext(): Promise<Result<TransactionContext>>;
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>;
38
41
  }
39
42
 
40
43
  declare type PrismaPgOptions = {
package/dist/index.d.ts CHANGED
@@ -1,13 +1,12 @@
1
1
  import type { ConnectionInfo } from '@prisma/driver-adapter-utils';
2
- import type { DriverAdapter } from '@prisma/driver-adapter-utils';
3
2
  import pg from 'pg';
4
- import type { Query } from '@prisma/driver-adapter-utils';
5
- import type { Queryable } from '@prisma/driver-adapter-utils';
6
- import type { Result } from '@prisma/driver-adapter-utils';
7
- import type { ResultSet } from '@prisma/driver-adapter-utils';
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';
8
7
  import type { TransactionContext } from '@prisma/driver-adapter-utils';
9
8
 
10
- declare class PgQueryable<ClientT extends StdClient | TransactionClient> implements Queryable {
9
+ declare class PgQueryable<ClientT extends StdClient | TransactionClient> implements SqlQueryable {
11
10
  protected readonly client: ClientT;
12
11
  readonly provider = "postgres";
13
12
  readonly adapterName: string;
@@ -15,26 +14,30 @@ declare class PgQueryable<ClientT extends StdClient | TransactionClient> impleme
15
14
  /**
16
15
  * Execute a query given as SQL, interpolating the given parameters.
17
16
  */
18
- queryRaw(query: Query): Promise<Result<ResultSet>>;
17
+ queryRaw(query: SqlQuery): Promise<SqlResultSet>;
19
18
  /**
20
19
  * Execute a query given as SQL, interpolating the given parameters and
21
20
  * returning the number of affected rows.
22
21
  * Note: Queryable expects a u64, but napi.rs only supports u32.
23
22
  */
24
- executeRaw(query: Query): Promise<Result<number>>;
23
+ executeRaw(query: SqlQuery): Promise<number>;
25
24
  /**
26
25
  * Run a query against the database, returning the result set.
27
26
  * Should the query fail due to a connection error, the connection is
28
27
  * marked as unhealthy.
29
28
  */
30
29
  private performIO;
30
+ protected onError(error: any): never;
31
31
  }
32
32
 
33
- export declare class PrismaPg extends PgQueryable<StdClient> implements DriverAdapter {
33
+ export declare class PrismaPg extends PgQueryable<StdClient> implements SqlConnection {
34
34
  private options?;
35
- constructor(client: pg.Pool, options?: PrismaPgOptions | undefined);
36
- getConnectionInfo(): Result<ConnectionInfo>;
37
- transactionContext(): Promise<Result<TransactionContext>>;
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>;
38
41
  }
39
42
 
40
43
  declare type PrismaPgOptions = {
package/dist/index.js CHANGED
@@ -383,29 +383,25 @@ var PgQueryable = class {
383
383
  async queryRaw(query) {
384
384
  const tag = "[js::query_raw]";
385
385
  debug(`${tag} %O`, query);
386
- const res = await this.performIO(query);
387
- if (!res.ok) {
388
- return (0, import_driver_adapter_utils2.err)(res.error);
389
- }
390
- const { fields, rows } = res.value;
386
+ const { fields, rows } = await this.performIO(query);
391
387
  const columnNames = fields.map((field) => field.name);
392
388
  let columnTypes = [];
393
389
  try {
394
390
  columnTypes = fields.map((field) => fieldToColumnType(field.dataTypeID));
395
391
  } catch (e) {
396
392
  if (e instanceof UnsupportedNativeDataType) {
397
- return (0, import_driver_adapter_utils2.err)({
393
+ throw new import_driver_adapter_utils2.DriverAdapterError({
398
394
  kind: "UnsupportedNativeDataType",
399
395
  type: e.type
400
396
  });
401
397
  }
402
398
  throw e;
403
399
  }
404
- return (0, import_driver_adapter_utils2.ok)({
400
+ return {
405
401
  columnNames,
406
402
  columnTypes,
407
403
  rows
408
- });
404
+ };
409
405
  }
410
406
  /**
411
407
  * Execute a query given as SQL, interpolating the given parameters and
@@ -415,7 +411,7 @@ var PgQueryable = class {
415
411
  async executeRaw(query) {
416
412
  const tag = "[js::execute_raw]";
417
413
  debug(`${tag} %O`, query);
418
- return (await this.performIO(query)).map(({ rowCount: rowsAffected }) => rowsAffected ?? 0);
414
+ return (await this.performIO(query)).rowCount ?? 0;
419
415
  }
420
416
  /**
421
417
  * Run a query against the database, returning the result set.
@@ -453,23 +449,25 @@ var PgQueryable = class {
453
449
  },
454
450
  fixArrayBufferValues(values)
455
451
  );
456
- return (0, import_driver_adapter_utils2.ok)(result);
452
+ return result;
457
453
  } catch (e) {
458
- const error = e;
459
- debug("Error in performIO: %O", error);
460
- if (e && typeof e.code === "string" && typeof e.severity === "string" && typeof e.message === "string") {
461
- return (0, import_driver_adapter_utils2.err)({
462
- kind: "postgres",
463
- code: e.code,
464
- severity: e.severity,
465
- message: e.message,
466
- detail: e.detail,
467
- column: e.column,
468
- hint: e.hint
469
- });
470
- }
471
- throw error;
454
+ this.onError(e);
455
+ }
456
+ }
457
+ onError(error) {
458
+ debug("Error in performIO: %O", error);
459
+ if (error && typeof error.code === "string" && typeof error.severity === "string" && typeof error.message === "string") {
460
+ throw new import_driver_adapter_utils2.DriverAdapterError({
461
+ kind: "postgres",
462
+ code: error.code,
463
+ severity: error.severity,
464
+ message: error.message,
465
+ detail: error.detail,
466
+ column: error.column,
467
+ hint: error.hint
468
+ });
472
469
  }
470
+ throw error;
473
471
  }
474
472
  };
475
473
  var PgTransaction = class extends PgQueryable {
@@ -480,12 +478,10 @@ var PgTransaction = class extends PgQueryable {
480
478
  async commit() {
481
479
  debug(`[js::commit]`);
482
480
  this.client.release();
483
- return (0, import_driver_adapter_utils2.ok)(void 0);
484
481
  }
485
482
  async rollback() {
486
483
  debug(`[js::rollback]`);
487
484
  this.client.release();
488
- return (0, import_driver_adapter_utils2.ok)(void 0);
489
485
  }
490
486
  };
491
487
  var PgTransactionContext = class extends PgQueryable {
@@ -499,11 +495,11 @@ var PgTransactionContext = class extends PgQueryable {
499
495
  };
500
496
  const tag = "[js::startTransaction]";
501
497
  debug("%s options: %O", tag, options);
502
- return (0, import_driver_adapter_utils2.ok)(new PgTransaction(this.conn, options));
498
+ return new PgTransaction(this.conn, options);
503
499
  }
504
500
  };
505
501
  var PrismaPg = class extends PgQueryable {
506
- constructor(client, options) {
502
+ constructor(client, options, release) {
507
503
  if (!(client instanceof import_pg2.default.Pool)) {
508
504
  throw new TypeError(`PrismaPg must be initialized with an instance of Pool:
509
505
  import { Pool } from 'pg'
@@ -513,15 +509,29 @@ const adapter = new PrismaPg(pool)
513
509
  }
514
510
  super(client);
515
511
  this.options = options;
512
+ this.release = release;
513
+ }
514
+ async executeScript(script) {
515
+ for (const stmt of script.split(";")) {
516
+ try {
517
+ await this.client.query(stmt);
518
+ } catch (error) {
519
+ this.onError(error);
520
+ }
521
+ }
516
522
  }
517
523
  getConnectionInfo() {
518
- return (0, import_driver_adapter_utils2.ok)({
524
+ return {
519
525
  schemaName: this.options?.schema
520
- });
526
+ };
521
527
  }
522
528
  async transactionContext() {
523
529
  const conn = await this.client.connect();
524
- return (0, import_driver_adapter_utils2.ok)(new PgTransactionContext(conn));
530
+ return new PgTransactionContext(conn);
531
+ }
532
+ async dispose() {
533
+ await this.release?.();
534
+ return await this.client.end();
525
535
  }
526
536
  };
527
537
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/pg.ts
2
- import { Debug, err, ok } from "@prisma/driver-adapter-utils";
2
+ import { Debug, DriverAdapterError } from "@prisma/driver-adapter-utils";
3
3
  import pg2 from "pg";
4
4
 
5
5
  // package.json
@@ -347,29 +347,25 @@ var PgQueryable = class {
347
347
  async queryRaw(query) {
348
348
  const tag = "[js::query_raw]";
349
349
  debug(`${tag} %O`, query);
350
- const res = await this.performIO(query);
351
- if (!res.ok) {
352
- return err(res.error);
353
- }
354
- const { fields, rows } = res.value;
350
+ const { fields, rows } = await this.performIO(query);
355
351
  const columnNames = fields.map((field) => field.name);
356
352
  let columnTypes = [];
357
353
  try {
358
354
  columnTypes = fields.map((field) => fieldToColumnType(field.dataTypeID));
359
355
  } catch (e) {
360
356
  if (e instanceof UnsupportedNativeDataType) {
361
- return err({
357
+ throw new DriverAdapterError({
362
358
  kind: "UnsupportedNativeDataType",
363
359
  type: e.type
364
360
  });
365
361
  }
366
362
  throw e;
367
363
  }
368
- return ok({
364
+ return {
369
365
  columnNames,
370
366
  columnTypes,
371
367
  rows
372
- });
368
+ };
373
369
  }
374
370
  /**
375
371
  * Execute a query given as SQL, interpolating the given parameters and
@@ -379,7 +375,7 @@ var PgQueryable = class {
379
375
  async executeRaw(query) {
380
376
  const tag = "[js::execute_raw]";
381
377
  debug(`${tag} %O`, query);
382
- return (await this.performIO(query)).map(({ rowCount: rowsAffected }) => rowsAffected ?? 0);
378
+ return (await this.performIO(query)).rowCount ?? 0;
383
379
  }
384
380
  /**
385
381
  * Run a query against the database, returning the result set.
@@ -417,23 +413,25 @@ var PgQueryable = class {
417
413
  },
418
414
  fixArrayBufferValues(values)
419
415
  );
420
- return ok(result);
416
+ return result;
421
417
  } catch (e) {
422
- const error = e;
423
- debug("Error in performIO: %O", error);
424
- if (e && typeof e.code === "string" && typeof e.severity === "string" && typeof e.message === "string") {
425
- return err({
426
- kind: "postgres",
427
- code: e.code,
428
- severity: e.severity,
429
- message: e.message,
430
- detail: e.detail,
431
- column: e.column,
432
- hint: e.hint
433
- });
434
- }
435
- throw error;
418
+ this.onError(e);
419
+ }
420
+ }
421
+ onError(error) {
422
+ debug("Error in performIO: %O", error);
423
+ if (error && typeof error.code === "string" && typeof error.severity === "string" && typeof error.message === "string") {
424
+ throw new DriverAdapterError({
425
+ kind: "postgres",
426
+ code: error.code,
427
+ severity: error.severity,
428
+ message: error.message,
429
+ detail: error.detail,
430
+ column: error.column,
431
+ hint: error.hint
432
+ });
436
433
  }
434
+ throw error;
437
435
  }
438
436
  };
439
437
  var PgTransaction = class extends PgQueryable {
@@ -444,12 +442,10 @@ var PgTransaction = class extends PgQueryable {
444
442
  async commit() {
445
443
  debug(`[js::commit]`);
446
444
  this.client.release();
447
- return ok(void 0);
448
445
  }
449
446
  async rollback() {
450
447
  debug(`[js::rollback]`);
451
448
  this.client.release();
452
- return ok(void 0);
453
449
  }
454
450
  };
455
451
  var PgTransactionContext = class extends PgQueryable {
@@ -463,11 +459,11 @@ var PgTransactionContext = class extends PgQueryable {
463
459
  };
464
460
  const tag = "[js::startTransaction]";
465
461
  debug("%s options: %O", tag, options);
466
- return ok(new PgTransaction(this.conn, options));
462
+ return new PgTransaction(this.conn, options);
467
463
  }
468
464
  };
469
465
  var PrismaPg = class extends PgQueryable {
470
- constructor(client, options) {
466
+ constructor(client, options, release) {
471
467
  if (!(client instanceof pg2.Pool)) {
472
468
  throw new TypeError(`PrismaPg must be initialized with an instance of Pool:
473
469
  import { Pool } from 'pg'
@@ -477,15 +473,29 @@ const adapter = new PrismaPg(pool)
477
473
  }
478
474
  super(client);
479
475
  this.options = options;
476
+ this.release = release;
477
+ }
478
+ async executeScript(script) {
479
+ for (const stmt of script.split(";")) {
480
+ try {
481
+ await this.client.query(stmt);
482
+ } catch (error) {
483
+ this.onError(error);
484
+ }
485
+ }
480
486
  }
481
487
  getConnectionInfo() {
482
- return ok({
488
+ return {
483
489
  schemaName: this.options?.schema
484
- });
490
+ };
485
491
  }
486
492
  async transactionContext() {
487
493
  const conn = await this.client.connect();
488
- return ok(new PgTransactionContext(conn));
494
+ return new PgTransactionContext(conn);
495
+ }
496
+ async dispose() {
497
+ await this.release?.();
498
+ return await this.client.end();
489
499
  }
490
500
  };
491
501
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-pg",
3
- "version": "6.5.0-integration-fix-e2e-prisma-config-2.9",
3
+ "version": "6.5.0-integration-fix-client-read-replicas.2",
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.2",
35
- "@prisma/driver-adapter-utils": "6.5.0-integration-fix-e2e-prisma-config-2.9"
35
+ "@prisma/driver-adapter-utils": "6.5.0-integration-fix-client-read-replicas.2"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@swc/core": "1.10.11",