@prisma/adapter-pg 6.6.0-dev.8 → 6.6.0-dev.80

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
@@ -5,7 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
8
  var __export = (target, all) => {
10
9
  for (var name2 in all)
11
10
  __defProp(target, name2, { get: all[name2], enumerable: true });
@@ -27,12 +26,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
26
  mod
28
27
  ));
29
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
31
29
 
32
30
  // src/index.ts
33
31
  var index_exports = {};
34
32
  __export(index_exports, {
35
- PrismaPg: () => PrismaPg
33
+ PrismaPg: () => PrismaPgAdapterFactory
36
34
  });
37
35
  module.exports = __toCommonJS(index_exports);
38
36
 
@@ -76,130 +74,129 @@ var ArrayColumnType = {
76
74
  VARCHAR_ARRAY: 1015,
77
75
  XML_ARRAY: 143
78
76
  };
79
- var _UnsupportedNativeDataType = class _UnsupportedNativeDataType extends Error {
77
+ var UnsupportedNativeDataType = class _UnsupportedNativeDataType extends Error {
78
+ // map of type codes to type names
79
+ static typeNames = {
80
+ 16: "bool",
81
+ 17: "bytea",
82
+ 18: "char",
83
+ 19: "name",
84
+ 20: "int8",
85
+ 21: "int2",
86
+ 22: "int2vector",
87
+ 23: "int4",
88
+ 24: "regproc",
89
+ 25: "text",
90
+ 26: "oid",
91
+ 27: "tid",
92
+ 28: "xid",
93
+ 29: "cid",
94
+ 30: "oidvector",
95
+ 32: "pg_ddl_command",
96
+ 71: "pg_type",
97
+ 75: "pg_attribute",
98
+ 81: "pg_proc",
99
+ 83: "pg_class",
100
+ 114: "json",
101
+ 142: "xml",
102
+ 194: "pg_node_tree",
103
+ 269: "table_am_handler",
104
+ 325: "index_am_handler",
105
+ 600: "point",
106
+ 601: "lseg",
107
+ 602: "path",
108
+ 603: "box",
109
+ 604: "polygon",
110
+ 628: "line",
111
+ 650: "cidr",
112
+ 700: "float4",
113
+ 701: "float8",
114
+ 705: "unknown",
115
+ 718: "circle",
116
+ 774: "macaddr8",
117
+ 790: "money",
118
+ 829: "macaddr",
119
+ 869: "inet",
120
+ 1033: "aclitem",
121
+ 1042: "bpchar",
122
+ 1043: "varchar",
123
+ 1082: "date",
124
+ 1083: "time",
125
+ 1114: "timestamp",
126
+ 1184: "timestamptz",
127
+ 1186: "interval",
128
+ 1266: "timetz",
129
+ 1560: "bit",
130
+ 1562: "varbit",
131
+ 1700: "numeric",
132
+ 1790: "refcursor",
133
+ 2202: "regprocedure",
134
+ 2203: "regoper",
135
+ 2204: "regoperator",
136
+ 2205: "regclass",
137
+ 2206: "regtype",
138
+ 2249: "record",
139
+ 2275: "cstring",
140
+ 2276: "any",
141
+ 2277: "anyarray",
142
+ 2278: "void",
143
+ 2279: "trigger",
144
+ 2280: "language_handler",
145
+ 2281: "internal",
146
+ 2283: "anyelement",
147
+ 2287: "_record",
148
+ 2776: "anynonarray",
149
+ 2950: "uuid",
150
+ 2970: "txid_snapshot",
151
+ 3115: "fdw_handler",
152
+ 3220: "pg_lsn",
153
+ 3310: "tsm_handler",
154
+ 3361: "pg_ndistinct",
155
+ 3402: "pg_dependencies",
156
+ 3500: "anyenum",
157
+ 3614: "tsvector",
158
+ 3615: "tsquery",
159
+ 3642: "gtsvector",
160
+ 3734: "regconfig",
161
+ 3769: "regdictionary",
162
+ 3802: "jsonb",
163
+ 3831: "anyrange",
164
+ 3838: "event_trigger",
165
+ 3904: "int4range",
166
+ 3906: "numrange",
167
+ 3908: "tsrange",
168
+ 3910: "tstzrange",
169
+ 3912: "daterange",
170
+ 3926: "int8range",
171
+ 4072: "jsonpath",
172
+ 4089: "regnamespace",
173
+ 4096: "regrole",
174
+ 4191: "regcollation",
175
+ 4451: "int4multirange",
176
+ 4532: "nummultirange",
177
+ 4533: "tsmultirange",
178
+ 4534: "tstzmultirange",
179
+ 4535: "datemultirange",
180
+ 4536: "int8multirange",
181
+ 4537: "anymultirange",
182
+ 4538: "anycompatiblemultirange",
183
+ 4600: "pg_brin_bloom_summary",
184
+ 4601: "pg_brin_minmax_multi_summary",
185
+ 5017: "pg_mcv_list",
186
+ 5038: "pg_snapshot",
187
+ 5069: "xid8",
188
+ 5077: "anycompatible",
189
+ 5078: "anycompatiblearray",
190
+ 5079: "anycompatiblenonarray",
191
+ 5080: "anycompatiblerange"
192
+ };
193
+ type;
80
194
  constructor(code) {
81
195
  super();
82
- __publicField(this, "type");
83
196
  this.type = _UnsupportedNativeDataType.typeNames[code] || "Unknown";
84
197
  this.message = `Unsupported column type ${this.type}`;
85
198
  }
86
199
  };
87
- // map of type codes to type names
88
- __publicField(_UnsupportedNativeDataType, "typeNames", {
89
- 16: "bool",
90
- 17: "bytea",
91
- 18: "char",
92
- 19: "name",
93
- 20: "int8",
94
- 21: "int2",
95
- 22: "int2vector",
96
- 23: "int4",
97
- 24: "regproc",
98
- 25: "text",
99
- 26: "oid",
100
- 27: "tid",
101
- 28: "xid",
102
- 29: "cid",
103
- 30: "oidvector",
104
- 32: "pg_ddl_command",
105
- 71: "pg_type",
106
- 75: "pg_attribute",
107
- 81: "pg_proc",
108
- 83: "pg_class",
109
- 114: "json",
110
- 142: "xml",
111
- 194: "pg_node_tree",
112
- 269: "table_am_handler",
113
- 325: "index_am_handler",
114
- 600: "point",
115
- 601: "lseg",
116
- 602: "path",
117
- 603: "box",
118
- 604: "polygon",
119
- 628: "line",
120
- 650: "cidr",
121
- 700: "float4",
122
- 701: "float8",
123
- 705: "unknown",
124
- 718: "circle",
125
- 774: "macaddr8",
126
- 790: "money",
127
- 829: "macaddr",
128
- 869: "inet",
129
- 1033: "aclitem",
130
- 1042: "bpchar",
131
- 1043: "varchar",
132
- 1082: "date",
133
- 1083: "time",
134
- 1114: "timestamp",
135
- 1184: "timestamptz",
136
- 1186: "interval",
137
- 1266: "timetz",
138
- 1560: "bit",
139
- 1562: "varbit",
140
- 1700: "numeric",
141
- 1790: "refcursor",
142
- 2202: "regprocedure",
143
- 2203: "regoper",
144
- 2204: "regoperator",
145
- 2205: "regclass",
146
- 2206: "regtype",
147
- 2249: "record",
148
- 2275: "cstring",
149
- 2276: "any",
150
- 2277: "anyarray",
151
- 2278: "void",
152
- 2279: "trigger",
153
- 2280: "language_handler",
154
- 2281: "internal",
155
- 2283: "anyelement",
156
- 2287: "_record",
157
- 2776: "anynonarray",
158
- 2950: "uuid",
159
- 2970: "txid_snapshot",
160
- 3115: "fdw_handler",
161
- 3220: "pg_lsn",
162
- 3310: "tsm_handler",
163
- 3361: "pg_ndistinct",
164
- 3402: "pg_dependencies",
165
- 3500: "anyenum",
166
- 3614: "tsvector",
167
- 3615: "tsquery",
168
- 3642: "gtsvector",
169
- 3734: "regconfig",
170
- 3769: "regdictionary",
171
- 3802: "jsonb",
172
- 3831: "anyrange",
173
- 3838: "event_trigger",
174
- 3904: "int4range",
175
- 3906: "numrange",
176
- 3908: "tsrange",
177
- 3910: "tstzrange",
178
- 3912: "daterange",
179
- 3926: "int8range",
180
- 4072: "jsonpath",
181
- 4089: "regnamespace",
182
- 4096: "regrole",
183
- 4191: "regcollation",
184
- 4451: "int4multirange",
185
- 4532: "nummultirange",
186
- 4533: "tsmultirange",
187
- 4534: "tstzmultirange",
188
- 4535: "datemultirange",
189
- 4536: "int8multirange",
190
- 4537: "anymultirange",
191
- 4538: "anycompatiblemultirange",
192
- 4600: "pg_brin_bloom_summary",
193
- 4601: "pg_brin_minmax_multi_summary",
194
- 5017: "pg_mcv_list",
195
- 5038: "pg_snapshot",
196
- 5069: "xid8",
197
- 5077: "anycompatible",
198
- 5078: "anycompatiblearray",
199
- 5079: "anycompatiblenonarray",
200
- 5080: "anycompatiblerange"
201
- });
202
- var UnsupportedNativeDataType = _UnsupportedNativeDataType;
203
200
  function fieldToColumnType(fieldTypeId) {
204
201
  switch (fieldTypeId) {
205
202
  case ScalarColumnType.INT2:
@@ -377,9 +374,9 @@ var debug = (0, import_driver_adapter_utils2.Debug)("prisma:driver-adapter:pg");
377
374
  var PgQueryable = class {
378
375
  constructor(client) {
379
376
  this.client = client;
380
- __publicField(this, "provider", "postgres");
381
- __publicField(this, "adapterName", name);
382
377
  }
378
+ provider = "postgres";
379
+ adapterName = name;
383
380
  /**
384
381
  * Execute a query given as SQL, interpolating the given parameters.
385
382
  */
@@ -487,32 +484,34 @@ var PgTransaction = class extends PgQueryable {
487
484
  this.client.release();
488
485
  }
489
486
  };
490
- var PgTransactionContext = class extends PgQueryable {
491
- constructor(conn) {
492
- super(conn);
493
- 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;
494
492
  }
495
- async startTransaction() {
493
+ async startTransaction(isolationLevel) {
496
494
  const options = {
497
495
  usePhantomQuery: false
498
496
  };
499
497
  const tag = "[js::startTransaction]";
500
498
  debug("%s options: %O", tag, options);
501
- return new PgTransaction(this.conn, options);
502
- }
503
- };
504
- var PrismaPg = class extends PgQueryable {
505
- constructor(client, options, release) {
506
- if (!client) {
507
- throw new TypeError(`PrismaPg must be initialized with an instance of Pool:
508
- import { Pool } from 'pg'
509
- const pool = new Pool({ connectionString: url })
510
- const adapter = new PrismaPg(pool)
511
- `);
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;
512
514
  }
513
- super(client);
514
- this.options = options;
515
- this.release = release;
516
515
  }
517
516
  async executeScript(script) {
518
517
  for (const stmt of script.split(";")) {
@@ -528,15 +527,32 @@ const adapter = new PrismaPg(pool)
528
527
  schemaName: this.options?.schema
529
528
  };
530
529
  }
531
- async transactionContext() {
532
- const conn = await this.client.connect();
533
- return new PgTransactionContext(conn);
534
- }
535
530
  async dispose() {
536
531
  await this.release?.();
537
532
  return await this.client.end();
538
533
  }
539
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
+ };
540
556
  // Annotate the CommonJS export names for ESM import in node:
541
557
  0 && (module.exports = {
542
558
  PrismaPg
package/dist/index.mjs CHANGED
@@ -1,7 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
-
5
1
  // src/pg.ts
6
2
  import { Debug, DriverAdapterError } from "@prisma/driver-adapter-utils";
7
3
  import pg2 from "pg";
@@ -42,130 +38,129 @@ var ArrayColumnType = {
42
38
  VARCHAR_ARRAY: 1015,
43
39
  XML_ARRAY: 143
44
40
  };
45
- var _UnsupportedNativeDataType = class _UnsupportedNativeDataType extends Error {
41
+ var UnsupportedNativeDataType = class _UnsupportedNativeDataType extends Error {
42
+ // map of type codes to type names
43
+ static typeNames = {
44
+ 16: "bool",
45
+ 17: "bytea",
46
+ 18: "char",
47
+ 19: "name",
48
+ 20: "int8",
49
+ 21: "int2",
50
+ 22: "int2vector",
51
+ 23: "int4",
52
+ 24: "regproc",
53
+ 25: "text",
54
+ 26: "oid",
55
+ 27: "tid",
56
+ 28: "xid",
57
+ 29: "cid",
58
+ 30: "oidvector",
59
+ 32: "pg_ddl_command",
60
+ 71: "pg_type",
61
+ 75: "pg_attribute",
62
+ 81: "pg_proc",
63
+ 83: "pg_class",
64
+ 114: "json",
65
+ 142: "xml",
66
+ 194: "pg_node_tree",
67
+ 269: "table_am_handler",
68
+ 325: "index_am_handler",
69
+ 600: "point",
70
+ 601: "lseg",
71
+ 602: "path",
72
+ 603: "box",
73
+ 604: "polygon",
74
+ 628: "line",
75
+ 650: "cidr",
76
+ 700: "float4",
77
+ 701: "float8",
78
+ 705: "unknown",
79
+ 718: "circle",
80
+ 774: "macaddr8",
81
+ 790: "money",
82
+ 829: "macaddr",
83
+ 869: "inet",
84
+ 1033: "aclitem",
85
+ 1042: "bpchar",
86
+ 1043: "varchar",
87
+ 1082: "date",
88
+ 1083: "time",
89
+ 1114: "timestamp",
90
+ 1184: "timestamptz",
91
+ 1186: "interval",
92
+ 1266: "timetz",
93
+ 1560: "bit",
94
+ 1562: "varbit",
95
+ 1700: "numeric",
96
+ 1790: "refcursor",
97
+ 2202: "regprocedure",
98
+ 2203: "regoper",
99
+ 2204: "regoperator",
100
+ 2205: "regclass",
101
+ 2206: "regtype",
102
+ 2249: "record",
103
+ 2275: "cstring",
104
+ 2276: "any",
105
+ 2277: "anyarray",
106
+ 2278: "void",
107
+ 2279: "trigger",
108
+ 2280: "language_handler",
109
+ 2281: "internal",
110
+ 2283: "anyelement",
111
+ 2287: "_record",
112
+ 2776: "anynonarray",
113
+ 2950: "uuid",
114
+ 2970: "txid_snapshot",
115
+ 3115: "fdw_handler",
116
+ 3220: "pg_lsn",
117
+ 3310: "tsm_handler",
118
+ 3361: "pg_ndistinct",
119
+ 3402: "pg_dependencies",
120
+ 3500: "anyenum",
121
+ 3614: "tsvector",
122
+ 3615: "tsquery",
123
+ 3642: "gtsvector",
124
+ 3734: "regconfig",
125
+ 3769: "regdictionary",
126
+ 3802: "jsonb",
127
+ 3831: "anyrange",
128
+ 3838: "event_trigger",
129
+ 3904: "int4range",
130
+ 3906: "numrange",
131
+ 3908: "tsrange",
132
+ 3910: "tstzrange",
133
+ 3912: "daterange",
134
+ 3926: "int8range",
135
+ 4072: "jsonpath",
136
+ 4089: "regnamespace",
137
+ 4096: "regrole",
138
+ 4191: "regcollation",
139
+ 4451: "int4multirange",
140
+ 4532: "nummultirange",
141
+ 4533: "tsmultirange",
142
+ 4534: "tstzmultirange",
143
+ 4535: "datemultirange",
144
+ 4536: "int8multirange",
145
+ 4537: "anymultirange",
146
+ 4538: "anycompatiblemultirange",
147
+ 4600: "pg_brin_bloom_summary",
148
+ 4601: "pg_brin_minmax_multi_summary",
149
+ 5017: "pg_mcv_list",
150
+ 5038: "pg_snapshot",
151
+ 5069: "xid8",
152
+ 5077: "anycompatible",
153
+ 5078: "anycompatiblearray",
154
+ 5079: "anycompatiblenonarray",
155
+ 5080: "anycompatiblerange"
156
+ };
157
+ type;
46
158
  constructor(code) {
47
159
  super();
48
- __publicField(this, "type");
49
160
  this.type = _UnsupportedNativeDataType.typeNames[code] || "Unknown";
50
161
  this.message = `Unsupported column type ${this.type}`;
51
162
  }
52
163
  };
53
- // map of type codes to type names
54
- __publicField(_UnsupportedNativeDataType, "typeNames", {
55
- 16: "bool",
56
- 17: "bytea",
57
- 18: "char",
58
- 19: "name",
59
- 20: "int8",
60
- 21: "int2",
61
- 22: "int2vector",
62
- 23: "int4",
63
- 24: "regproc",
64
- 25: "text",
65
- 26: "oid",
66
- 27: "tid",
67
- 28: "xid",
68
- 29: "cid",
69
- 30: "oidvector",
70
- 32: "pg_ddl_command",
71
- 71: "pg_type",
72
- 75: "pg_attribute",
73
- 81: "pg_proc",
74
- 83: "pg_class",
75
- 114: "json",
76
- 142: "xml",
77
- 194: "pg_node_tree",
78
- 269: "table_am_handler",
79
- 325: "index_am_handler",
80
- 600: "point",
81
- 601: "lseg",
82
- 602: "path",
83
- 603: "box",
84
- 604: "polygon",
85
- 628: "line",
86
- 650: "cidr",
87
- 700: "float4",
88
- 701: "float8",
89
- 705: "unknown",
90
- 718: "circle",
91
- 774: "macaddr8",
92
- 790: "money",
93
- 829: "macaddr",
94
- 869: "inet",
95
- 1033: "aclitem",
96
- 1042: "bpchar",
97
- 1043: "varchar",
98
- 1082: "date",
99
- 1083: "time",
100
- 1114: "timestamp",
101
- 1184: "timestamptz",
102
- 1186: "interval",
103
- 1266: "timetz",
104
- 1560: "bit",
105
- 1562: "varbit",
106
- 1700: "numeric",
107
- 1790: "refcursor",
108
- 2202: "regprocedure",
109
- 2203: "regoper",
110
- 2204: "regoperator",
111
- 2205: "regclass",
112
- 2206: "regtype",
113
- 2249: "record",
114
- 2275: "cstring",
115
- 2276: "any",
116
- 2277: "anyarray",
117
- 2278: "void",
118
- 2279: "trigger",
119
- 2280: "language_handler",
120
- 2281: "internal",
121
- 2283: "anyelement",
122
- 2287: "_record",
123
- 2776: "anynonarray",
124
- 2950: "uuid",
125
- 2970: "txid_snapshot",
126
- 3115: "fdw_handler",
127
- 3220: "pg_lsn",
128
- 3310: "tsm_handler",
129
- 3361: "pg_ndistinct",
130
- 3402: "pg_dependencies",
131
- 3500: "anyenum",
132
- 3614: "tsvector",
133
- 3615: "tsquery",
134
- 3642: "gtsvector",
135
- 3734: "regconfig",
136
- 3769: "regdictionary",
137
- 3802: "jsonb",
138
- 3831: "anyrange",
139
- 3838: "event_trigger",
140
- 3904: "int4range",
141
- 3906: "numrange",
142
- 3908: "tsrange",
143
- 3910: "tstzrange",
144
- 3912: "daterange",
145
- 3926: "int8range",
146
- 4072: "jsonpath",
147
- 4089: "regnamespace",
148
- 4096: "regrole",
149
- 4191: "regcollation",
150
- 4451: "int4multirange",
151
- 4532: "nummultirange",
152
- 4533: "tsmultirange",
153
- 4534: "tstzmultirange",
154
- 4535: "datemultirange",
155
- 4536: "int8multirange",
156
- 4537: "anymultirange",
157
- 4538: "anycompatiblemultirange",
158
- 4600: "pg_brin_bloom_summary",
159
- 4601: "pg_brin_minmax_multi_summary",
160
- 5017: "pg_mcv_list",
161
- 5038: "pg_snapshot",
162
- 5069: "xid8",
163
- 5077: "anycompatible",
164
- 5078: "anycompatiblearray",
165
- 5079: "anycompatiblenonarray",
166
- 5080: "anycompatiblerange"
167
- });
168
- var UnsupportedNativeDataType = _UnsupportedNativeDataType;
169
164
  function fieldToColumnType(fieldTypeId) {
170
165
  switch (fieldTypeId) {
171
166
  case ScalarColumnType.INT2:
@@ -343,9 +338,9 @@ var debug = Debug("prisma:driver-adapter:pg");
343
338
  var PgQueryable = class {
344
339
  constructor(client) {
345
340
  this.client = client;
346
- __publicField(this, "provider", "postgres");
347
- __publicField(this, "adapterName", name);
348
341
  }
342
+ provider = "postgres";
343
+ adapterName = name;
349
344
  /**
350
345
  * Execute a query given as SQL, interpolating the given parameters.
351
346
  */
@@ -453,32 +448,34 @@ var PgTransaction = class extends PgQueryable {
453
448
  this.client.release();
454
449
  }
455
450
  };
456
- var PgTransactionContext = class extends PgQueryable {
457
- constructor(conn) {
458
- super(conn);
459
- 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;
460
456
  }
461
- async startTransaction() {
457
+ async startTransaction(isolationLevel) {
462
458
  const options = {
463
459
  usePhantomQuery: false
464
460
  };
465
461
  const tag = "[js::startTransaction]";
466
462
  debug("%s options: %O", tag, options);
467
- return new PgTransaction(this.conn, options);
468
- }
469
- };
470
- var PrismaPg = class extends PgQueryable {
471
- constructor(client, options, release) {
472
- if (!client) {
473
- throw new TypeError(`PrismaPg must be initialized with an instance of Pool:
474
- import { Pool } from 'pg'
475
- const pool = new Pool({ connectionString: url })
476
- const adapter = new PrismaPg(pool)
477
- `);
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;
478
478
  }
479
- super(client);
480
- this.options = options;
481
- this.release = release;
482
479
  }
483
480
  async executeScript(script) {
484
481
  for (const stmt of script.split(";")) {
@@ -494,15 +491,32 @@ const adapter = new PrismaPg(pool)
494
491
  schemaName: this.options?.schema
495
492
  };
496
493
  }
497
- async transactionContext() {
498
- const conn = await this.client.connect();
499
- return new PgTransactionContext(conn);
500
- }
501
494
  async dispose() {
502
495
  await this.release?.();
503
496
  return await this.client.end();
504
497
  }
505
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
+ };
506
520
  export {
507
- PrismaPg
521
+ PrismaPgAdapterFactory as PrismaPg
508
522
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-pg",
3
- "version": "6.6.0-dev.8",
3
+ "version": "6.6.0-dev.80",
4
4
  "description": "Prisma's driver adapter for \"pg\"",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -31,8 +31,8 @@
31
31
  "license": "Apache-2.0",
32
32
  "sideEffects": false,
33
33
  "dependencies": {
34
- "postgres-array": "3.0.3",
35
- "@prisma/driver-adapter-utils": "6.6.0-dev.8"
34
+ "postgres-array": "3.0.4",
35
+ "@prisma/driver-adapter-utils": "6.6.0-dev.80"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@swc/core": "1.11.5",
@@ -40,7 +40,7 @@
40
40
  "@types/pg": "8.11.11",
41
41
  "jest": "29.7.0",
42
42
  "jest-junit": "16.0.0",
43
- "pg": "8.13.3"
43
+ "pg": "8.14.1"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "pg": "^8.11.3"