@prisma/adapter-neon 6.6.0-dev.7 → 6.6.0-dev.71

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,7 +47,7 @@ Update your Prisma Client instance to use the Neon serverless driver using a Web
47
47
 
48
48
  ```ts
49
49
  // Import needed packages
50
- import { Pool, neonConfig } from '@neondatabase/serverless'
50
+ import { neonConfig } from '@neondatabase/serverless'
51
51
  import { PrismaNeon } from '@prisma/adapter-neon'
52
52
  import { PrismaClient } from '@prisma/client'
53
53
  import ws from 'ws'
@@ -57,8 +57,7 @@ neonConfig.webSocketConstructor = ws
57
57
  const connectionString = `${process.env.DATABASE_URL}`
58
58
 
59
59
  // Init prisma client
60
- const pool = new Pool({ connectionString })
61
- const adapter = new PrismaNeon(pool)
60
+ const adapter = new PrismaNeon({ connectionString })
62
61
  const prisma = new PrismaClient({ adapter })
63
62
 
64
63
  // Use Prisma Client as normal
package/dist/index.d.mts CHANGED
@@ -1,66 +1,23 @@
1
- import type { ConnectionInfo } from '@prisma/driver-adapter-utils';
2
1
  import * as neon from '@neondatabase/serverless';
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 { SqlDriverAdapterFactory } from '@prisma/driver-adapter-utils';
8
4
 
9
- declare type ARRAY_MODE_ENABLED = true;
10
-
11
- /**
12
- * Base class for http client, ws client and ws transaction
13
- */
14
- declare abstract class NeonQueryable implements SqlQueryable {
5
+ export declare class PrismaNeon implements SqlDriverAdapterFactory {
6
+ private readonly config;
7
+ private options?;
15
8
  readonly provider = "postgres";
16
9
  readonly adapterName: string;
17
- /**
18
- * Execute a query given as SQL, interpolating the given parameters.
19
- */
20
- queryRaw(query: SqlQuery): Promise<SqlResultSet>;
21
- /**
22
- * Execute a query given as SQL, interpolating the given parameters and
23
- * returning the number of affected rows.
24
- * Note: Queryable expects a u64, but napi.rs only supports u32.
25
- */
26
- executeRaw(query: SqlQuery): Promise<number>;
27
- /**
28
- * Run a query against the database, returning the result set.
29
- * Should the query fail due to a connection error, the connection is
30
- * marked as unhealthy.
31
- */
32
- abstract performIO(query: SqlQuery): Promise<PerformIOResult>;
33
- }
34
-
35
- /**
36
- * Base class for WS-based queryables: top-level client and transaction
37
- */
38
- declare class NeonWsQueryable<ClientT extends neon.Pool | neon.PoolClient> extends NeonQueryable {
39
- protected client: ClientT;
40
- constructor(client: ClientT);
41
- performIO(query: SqlQuery): Promise<PerformIOResult>;
42
- protected onError(e: any): never;
43
- }
44
-
45
- declare type PerformIOResult = neon.QueryResult<any> | neon.FullQueryResults<ARRAY_MODE_ENABLED>;
46
-
47
- export declare class PrismaNeon extends NeonWsQueryable<neon.Pool> implements SqlConnection {
48
- private options?;
49
- private isRunning;
50
- constructor(pool: neon.Pool, options?: PrismaNeonOptions | undefined);
51
- executeScript(_script: string): Promise<void>;
52
- getConnectionInfo(): ConnectionInfo;
53
- transactionContext(): Promise<TransactionContext>;
54
- dispose(): Promise<void>;
10
+ constructor(config: neon.PoolConfig, options?: PrismaNeonOptions | undefined);
11
+ connect(): Promise<SqlDriverAdapter>;
55
12
  }
56
13
 
57
- export declare class PrismaNeonHTTP extends NeonQueryable implements SqlConnection {
58
- private client;
59
- constructor(client: neon.NeonQueryFunction<any, any>);
60
- executeScript(_script: string): Promise<void>;
61
- performIO(query: SqlQuery): Promise<PerformIOResult>;
62
- transactionContext(): Promise<TransactionContext>;
63
- dispose(): Promise<void>;
14
+ export declare class PrismaNeonHTTP implements SqlDriverAdapterFactory {
15
+ private readonly connectionString;
16
+ private readonly options;
17
+ readonly provider = "postgres";
18
+ readonly adapterName: string;
19
+ constructor(connectionString: string, options: neon.HTTPQueryOptions<boolean, boolean>);
20
+ connect(): Promise<SqlDriverAdapter>;
64
21
  }
65
22
 
66
23
  declare type PrismaNeonOptions = {
package/dist/index.d.ts CHANGED
@@ -1,66 +1,23 @@
1
- import type { ConnectionInfo } from '@prisma/driver-adapter-utils';
2
1
  import * as neon from '@neondatabase/serverless';
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 { SqlDriverAdapterFactory } from '@prisma/driver-adapter-utils';
8
4
 
9
- declare type ARRAY_MODE_ENABLED = true;
10
-
11
- /**
12
- * Base class for http client, ws client and ws transaction
13
- */
14
- declare abstract class NeonQueryable implements SqlQueryable {
5
+ export declare class PrismaNeon implements SqlDriverAdapterFactory {
6
+ private readonly config;
7
+ private options?;
15
8
  readonly provider = "postgres";
16
9
  readonly adapterName: string;
17
- /**
18
- * Execute a query given as SQL, interpolating the given parameters.
19
- */
20
- queryRaw(query: SqlQuery): Promise<SqlResultSet>;
21
- /**
22
- * Execute a query given as SQL, interpolating the given parameters and
23
- * returning the number of affected rows.
24
- * Note: Queryable expects a u64, but napi.rs only supports u32.
25
- */
26
- executeRaw(query: SqlQuery): Promise<number>;
27
- /**
28
- * Run a query against the database, returning the result set.
29
- * Should the query fail due to a connection error, the connection is
30
- * marked as unhealthy.
31
- */
32
- abstract performIO(query: SqlQuery): Promise<PerformIOResult>;
33
- }
34
-
35
- /**
36
- * Base class for WS-based queryables: top-level client and transaction
37
- */
38
- declare class NeonWsQueryable<ClientT extends neon.Pool | neon.PoolClient> extends NeonQueryable {
39
- protected client: ClientT;
40
- constructor(client: ClientT);
41
- performIO(query: SqlQuery): Promise<PerformIOResult>;
42
- protected onError(e: any): never;
43
- }
44
-
45
- declare type PerformIOResult = neon.QueryResult<any> | neon.FullQueryResults<ARRAY_MODE_ENABLED>;
46
-
47
- export declare class PrismaNeon extends NeonWsQueryable<neon.Pool> implements SqlConnection {
48
- private options?;
49
- private isRunning;
50
- constructor(pool: neon.Pool, options?: PrismaNeonOptions | undefined);
51
- executeScript(_script: string): Promise<void>;
52
- getConnectionInfo(): ConnectionInfo;
53
- transactionContext(): Promise<TransactionContext>;
54
- dispose(): Promise<void>;
10
+ constructor(config: neon.PoolConfig, options?: PrismaNeonOptions | undefined);
11
+ connect(): Promise<SqlDriverAdapter>;
55
12
  }
56
13
 
57
- export declare class PrismaNeonHTTP extends NeonQueryable implements SqlConnection {
58
- private client;
59
- constructor(client: neon.NeonQueryFunction<any, any>);
60
- executeScript(_script: string): Promise<void>;
61
- performIO(query: SqlQuery): Promise<PerformIOResult>;
62
- transactionContext(): Promise<TransactionContext>;
63
- dispose(): Promise<void>;
14
+ export declare class PrismaNeonHTTP implements SqlDriverAdapterFactory {
15
+ private readonly connectionString;
16
+ private readonly options;
17
+ readonly provider = "postgres";
18
+ readonly adapterName: string;
19
+ constructor(connectionString: string, options: neon.HTTPQueryOptions<boolean, boolean>);
20
+ connect(): Promise<SqlDriverAdapter>;
64
21
  }
65
22
 
66
23
  declare type PrismaNeonOptions = {
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,13 +26,12 @@ 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
- PrismaNeon: () => PrismaNeon,
36
- PrismaNeonHTTP: () => PrismaNeonHTTP
33
+ PrismaNeon: () => PrismaNeonAdapterFactory,
34
+ PrismaNeonHTTP: () => PrismaNeonHTTPAdapterFactory
37
35
  });
38
36
  module.exports = __toCommonJS(index_exports);
39
37
 
@@ -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:
@@ -374,10 +371,8 @@ function fixArrayBufferValues(values) {
374
371
  // src/neon.ts
375
372
  var debug = (0, import_driver_adapter_utils2.Debug)("prisma:driver-adapter:neon");
376
373
  var NeonQueryable = class {
377
- constructor() {
378
- __publicField(this, "provider", "postgres");
379
- __publicField(this, "adapterName", name);
380
- }
374
+ provider = "postgres";
375
+ adapterName = name;
381
376
  /**
382
377
  * Execute a query given as SQL, interpolating the given parameters.
383
378
  */
@@ -486,45 +481,43 @@ var NeonTransaction = class extends NeonWsQueryable {
486
481
  this.client.release();
487
482
  }
488
483
  };
489
- var NeonTransactionContext = class extends NeonWsQueryable {
490
- constructor(conn) {
491
- super(conn);
492
- this.conn = conn;
484
+ var PrismaNeonAdapter = class extends NeonWsQueryable {
485
+ constructor(pool, options) {
486
+ super(pool);
487
+ this.options = options;
493
488
  }
494
- async startTransaction() {
489
+ isRunning = true;
490
+ executeScript(_script) {
491
+ throw new Error("Not implemented yet");
492
+ }
493
+ async startTransaction(isolationLevel) {
495
494
  const options = {
496
495
  usePhantomQuery: false
497
496
  };
498
497
  const tag = "[js::startTransaction]";
499
498
  debug("%s options: %O", tag, options);
500
- return new NeonTransaction(this.conn, options);
501
- }
502
- };
503
- var PrismaNeon = class extends NeonWsQueryable {
504
- constructor(pool, options) {
505
- if (!(pool instanceof neon.Pool)) {
506
- throw new TypeError(`PrismaNeon must be initialized with an instance of Pool:
507
- import { Pool } from '@neondatabase/serverless'
508
- const pool = new Pool({ connectionString: url })
509
- const adapter = new PrismaNeon(pool)
510
- `);
499
+ const conn = await this.client.connect();
500
+ const tx = new NeonTransaction(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;
511
514
  }
512
- super(pool);
513
- this.options = options;
514
- __publicField(this, "isRunning", true);
515
- }
516
- executeScript(_script) {
517
- throw new Error("Not implemented yet");
518
515
  }
519
516
  getConnectionInfo() {
520
517
  return {
521
518
  schemaName: this.options?.schema
522
519
  };
523
520
  }
524
- async transactionContext() {
525
- const conn = await this.client.connect();
526
- return new NeonTransactionContext(conn);
527
- }
528
521
  async dispose() {
529
522
  if (this.isRunning) {
530
523
  await this.client.end();
@@ -532,15 +525,29 @@ const adapter = new PrismaNeon(pool)
532
525
  }
533
526
  }
534
527
  };
535
- var PrismaNeonHTTP = class extends NeonQueryable {
528
+ var PrismaNeonAdapterFactory = class {
529
+ constructor(config, options) {
530
+ this.config = config;
531
+ this.options = options;
532
+ }
533
+ provider = "postgres";
534
+ adapterName = name;
535
+ async connect() {
536
+ return new PrismaNeonAdapter(new neon.Pool(this.config), this.options);
537
+ }
538
+ };
539
+ var PrismaNeonHTTPAdapter = class extends NeonQueryable {
540
+ client;
536
541
  constructor(client) {
537
542
  super();
538
- __publicField(this, "client");
539
543
  this.client = client.query ?? client;
540
544
  }
541
545
  executeScript(_script) {
542
546
  throw new Error("Not implemented yet");
543
547
  }
548
+ async startTransaction() {
549
+ return Promise.reject(new Error("Transactions are not supported in HTTP mode"));
550
+ }
544
551
  async performIO(query) {
545
552
  const { sql, args: values } = query;
546
553
  return await this.client(sql, values, {
@@ -562,12 +569,20 @@ var PrismaNeonHTTP = class extends NeonQueryable {
562
569
  // https://github.com/neondatabase/serverless/pull/110#issuecomment-2458992991
563
570
  });
564
571
  }
565
- transactionContext() {
566
- return Promise.reject(new Error("Transactions are not supported in HTTP mode"));
567
- }
568
572
  async dispose() {
569
573
  }
570
574
  };
575
+ var PrismaNeonHTTPAdapterFactory = class {
576
+ constructor(connectionString, options) {
577
+ this.connectionString = connectionString;
578
+ this.options = options;
579
+ }
580
+ provider = "postgres";
581
+ adapterName = name;
582
+ async connect() {
583
+ return new PrismaNeonHTTPAdapter(neon.neon(this.connectionString, this.options));
584
+ }
585
+ };
571
586
  // Annotate the CommonJS export names for ESM import in node:
572
587
  0 && (module.exports = {
573
588
  PrismaNeon,
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/neon.ts
6
2
  import * as neon from "@neondatabase/serverless";
7
3
  import { Debug, DriverAdapterError } from "@prisma/driver-adapter-utils";
@@ -41,130 +37,129 @@ var ArrayColumnType = {
41
37
  VARCHAR_ARRAY: 1015,
42
38
  XML_ARRAY: 143
43
39
  };
44
- var _UnsupportedNativeDataType = class _UnsupportedNativeDataType extends Error {
40
+ var UnsupportedNativeDataType = class _UnsupportedNativeDataType extends Error {
41
+ // map of type codes to type names
42
+ static typeNames = {
43
+ 16: "bool",
44
+ 17: "bytea",
45
+ 18: "char",
46
+ 19: "name",
47
+ 20: "int8",
48
+ 21: "int2",
49
+ 22: "int2vector",
50
+ 23: "int4",
51
+ 24: "regproc",
52
+ 25: "text",
53
+ 26: "oid",
54
+ 27: "tid",
55
+ 28: "xid",
56
+ 29: "cid",
57
+ 30: "oidvector",
58
+ 32: "pg_ddl_command",
59
+ 71: "pg_type",
60
+ 75: "pg_attribute",
61
+ 81: "pg_proc",
62
+ 83: "pg_class",
63
+ 114: "json",
64
+ 142: "xml",
65
+ 194: "pg_node_tree",
66
+ 269: "table_am_handler",
67
+ 325: "index_am_handler",
68
+ 600: "point",
69
+ 601: "lseg",
70
+ 602: "path",
71
+ 603: "box",
72
+ 604: "polygon",
73
+ 628: "line",
74
+ 650: "cidr",
75
+ 700: "float4",
76
+ 701: "float8",
77
+ 705: "unknown",
78
+ 718: "circle",
79
+ 774: "macaddr8",
80
+ 790: "money",
81
+ 829: "macaddr",
82
+ 869: "inet",
83
+ 1033: "aclitem",
84
+ 1042: "bpchar",
85
+ 1043: "varchar",
86
+ 1082: "date",
87
+ 1083: "time",
88
+ 1114: "timestamp",
89
+ 1184: "timestamptz",
90
+ 1186: "interval",
91
+ 1266: "timetz",
92
+ 1560: "bit",
93
+ 1562: "varbit",
94
+ 1700: "numeric",
95
+ 1790: "refcursor",
96
+ 2202: "regprocedure",
97
+ 2203: "regoper",
98
+ 2204: "regoperator",
99
+ 2205: "regclass",
100
+ 2206: "regtype",
101
+ 2249: "record",
102
+ 2275: "cstring",
103
+ 2276: "any",
104
+ 2277: "anyarray",
105
+ 2278: "void",
106
+ 2279: "trigger",
107
+ 2280: "language_handler",
108
+ 2281: "internal",
109
+ 2283: "anyelement",
110
+ 2287: "_record",
111
+ 2776: "anynonarray",
112
+ 2950: "uuid",
113
+ 2970: "txid_snapshot",
114
+ 3115: "fdw_handler",
115
+ 3220: "pg_lsn",
116
+ 3310: "tsm_handler",
117
+ 3361: "pg_ndistinct",
118
+ 3402: "pg_dependencies",
119
+ 3500: "anyenum",
120
+ 3614: "tsvector",
121
+ 3615: "tsquery",
122
+ 3642: "gtsvector",
123
+ 3734: "regconfig",
124
+ 3769: "regdictionary",
125
+ 3802: "jsonb",
126
+ 3831: "anyrange",
127
+ 3838: "event_trigger",
128
+ 3904: "int4range",
129
+ 3906: "numrange",
130
+ 3908: "tsrange",
131
+ 3910: "tstzrange",
132
+ 3912: "daterange",
133
+ 3926: "int8range",
134
+ 4072: "jsonpath",
135
+ 4089: "regnamespace",
136
+ 4096: "regrole",
137
+ 4191: "regcollation",
138
+ 4451: "int4multirange",
139
+ 4532: "nummultirange",
140
+ 4533: "tsmultirange",
141
+ 4534: "tstzmultirange",
142
+ 4535: "datemultirange",
143
+ 4536: "int8multirange",
144
+ 4537: "anymultirange",
145
+ 4538: "anycompatiblemultirange",
146
+ 4600: "pg_brin_bloom_summary",
147
+ 4601: "pg_brin_minmax_multi_summary",
148
+ 5017: "pg_mcv_list",
149
+ 5038: "pg_snapshot",
150
+ 5069: "xid8",
151
+ 5077: "anycompatible",
152
+ 5078: "anycompatiblearray",
153
+ 5079: "anycompatiblenonarray",
154
+ 5080: "anycompatiblerange"
155
+ };
156
+ type;
45
157
  constructor(code) {
46
158
  super();
47
- __publicField(this, "type");
48
159
  this.type = _UnsupportedNativeDataType.typeNames[code] || "Unknown";
49
160
  this.message = `Unsupported column type ${this.type}`;
50
161
  }
51
162
  };
52
- // map of type codes to type names
53
- __publicField(_UnsupportedNativeDataType, "typeNames", {
54
- 16: "bool",
55
- 17: "bytea",
56
- 18: "char",
57
- 19: "name",
58
- 20: "int8",
59
- 21: "int2",
60
- 22: "int2vector",
61
- 23: "int4",
62
- 24: "regproc",
63
- 25: "text",
64
- 26: "oid",
65
- 27: "tid",
66
- 28: "xid",
67
- 29: "cid",
68
- 30: "oidvector",
69
- 32: "pg_ddl_command",
70
- 71: "pg_type",
71
- 75: "pg_attribute",
72
- 81: "pg_proc",
73
- 83: "pg_class",
74
- 114: "json",
75
- 142: "xml",
76
- 194: "pg_node_tree",
77
- 269: "table_am_handler",
78
- 325: "index_am_handler",
79
- 600: "point",
80
- 601: "lseg",
81
- 602: "path",
82
- 603: "box",
83
- 604: "polygon",
84
- 628: "line",
85
- 650: "cidr",
86
- 700: "float4",
87
- 701: "float8",
88
- 705: "unknown",
89
- 718: "circle",
90
- 774: "macaddr8",
91
- 790: "money",
92
- 829: "macaddr",
93
- 869: "inet",
94
- 1033: "aclitem",
95
- 1042: "bpchar",
96
- 1043: "varchar",
97
- 1082: "date",
98
- 1083: "time",
99
- 1114: "timestamp",
100
- 1184: "timestamptz",
101
- 1186: "interval",
102
- 1266: "timetz",
103
- 1560: "bit",
104
- 1562: "varbit",
105
- 1700: "numeric",
106
- 1790: "refcursor",
107
- 2202: "regprocedure",
108
- 2203: "regoper",
109
- 2204: "regoperator",
110
- 2205: "regclass",
111
- 2206: "regtype",
112
- 2249: "record",
113
- 2275: "cstring",
114
- 2276: "any",
115
- 2277: "anyarray",
116
- 2278: "void",
117
- 2279: "trigger",
118
- 2280: "language_handler",
119
- 2281: "internal",
120
- 2283: "anyelement",
121
- 2287: "_record",
122
- 2776: "anynonarray",
123
- 2950: "uuid",
124
- 2970: "txid_snapshot",
125
- 3115: "fdw_handler",
126
- 3220: "pg_lsn",
127
- 3310: "tsm_handler",
128
- 3361: "pg_ndistinct",
129
- 3402: "pg_dependencies",
130
- 3500: "anyenum",
131
- 3614: "tsvector",
132
- 3615: "tsquery",
133
- 3642: "gtsvector",
134
- 3734: "regconfig",
135
- 3769: "regdictionary",
136
- 3802: "jsonb",
137
- 3831: "anyrange",
138
- 3838: "event_trigger",
139
- 3904: "int4range",
140
- 3906: "numrange",
141
- 3908: "tsrange",
142
- 3910: "tstzrange",
143
- 3912: "daterange",
144
- 3926: "int8range",
145
- 4072: "jsonpath",
146
- 4089: "regnamespace",
147
- 4096: "regrole",
148
- 4191: "regcollation",
149
- 4451: "int4multirange",
150
- 4532: "nummultirange",
151
- 4533: "tsmultirange",
152
- 4534: "tstzmultirange",
153
- 4535: "datemultirange",
154
- 4536: "int8multirange",
155
- 4537: "anymultirange",
156
- 4538: "anycompatiblemultirange",
157
- 4600: "pg_brin_bloom_summary",
158
- 4601: "pg_brin_minmax_multi_summary",
159
- 5017: "pg_mcv_list",
160
- 5038: "pg_snapshot",
161
- 5069: "xid8",
162
- 5077: "anycompatible",
163
- 5078: "anycompatiblearray",
164
- 5079: "anycompatiblenonarray",
165
- 5080: "anycompatiblerange"
166
- });
167
- var UnsupportedNativeDataType = _UnsupportedNativeDataType;
168
163
  function fieldToColumnType(fieldTypeId) {
169
164
  switch (fieldTypeId) {
170
165
  case ScalarColumnType.INT2:
@@ -339,10 +334,8 @@ function fixArrayBufferValues(values) {
339
334
  // src/neon.ts
340
335
  var debug = Debug("prisma:driver-adapter:neon");
341
336
  var NeonQueryable = class {
342
- constructor() {
343
- __publicField(this, "provider", "postgres");
344
- __publicField(this, "adapterName", name);
345
- }
337
+ provider = "postgres";
338
+ adapterName = name;
346
339
  /**
347
340
  * Execute a query given as SQL, interpolating the given parameters.
348
341
  */
@@ -451,45 +444,43 @@ var NeonTransaction = class extends NeonWsQueryable {
451
444
  this.client.release();
452
445
  }
453
446
  };
454
- var NeonTransactionContext = class extends NeonWsQueryable {
455
- constructor(conn) {
456
- super(conn);
457
- this.conn = conn;
447
+ var PrismaNeonAdapter = class extends NeonWsQueryable {
448
+ constructor(pool, options) {
449
+ super(pool);
450
+ this.options = options;
458
451
  }
459
- async startTransaction() {
452
+ isRunning = true;
453
+ executeScript(_script) {
454
+ throw new Error("Not implemented yet");
455
+ }
456
+ async startTransaction(isolationLevel) {
460
457
  const options = {
461
458
  usePhantomQuery: false
462
459
  };
463
460
  const tag = "[js::startTransaction]";
464
461
  debug("%s options: %O", tag, options);
465
- return new NeonTransaction(this.conn, options);
466
- }
467
- };
468
- var PrismaNeon = class extends NeonWsQueryable {
469
- constructor(pool, options) {
470
- if (!(pool instanceof neon.Pool)) {
471
- throw new TypeError(`PrismaNeon must be initialized with an instance of Pool:
472
- import { Pool } from '@neondatabase/serverless'
473
- const pool = new Pool({ connectionString: url })
474
- const adapter = new PrismaNeon(pool)
475
- `);
462
+ const conn = await this.client.connect();
463
+ const tx = new NeonTransaction(conn, options);
464
+ try {
465
+ await tx.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
466
+ if (isolationLevel) {
467
+ await tx.executeRaw({
468
+ sql: `SET TRANSACTION ISOLATION LEVEL ${isolationLevel}`,
469
+ args: [],
470
+ argTypes: []
471
+ });
472
+ }
473
+ return tx;
474
+ } catch (error) {
475
+ conn.release(error);
476
+ throw error;
476
477
  }
477
- super(pool);
478
- this.options = options;
479
- __publicField(this, "isRunning", true);
480
- }
481
- executeScript(_script) {
482
- throw new Error("Not implemented yet");
483
478
  }
484
479
  getConnectionInfo() {
485
480
  return {
486
481
  schemaName: this.options?.schema
487
482
  };
488
483
  }
489
- async transactionContext() {
490
- const conn = await this.client.connect();
491
- return new NeonTransactionContext(conn);
492
- }
493
484
  async dispose() {
494
485
  if (this.isRunning) {
495
486
  await this.client.end();
@@ -497,15 +488,29 @@ const adapter = new PrismaNeon(pool)
497
488
  }
498
489
  }
499
490
  };
500
- var PrismaNeonHTTP = class extends NeonQueryable {
491
+ var PrismaNeonAdapterFactory = class {
492
+ constructor(config, options) {
493
+ this.config = config;
494
+ this.options = options;
495
+ }
496
+ provider = "postgres";
497
+ adapterName = name;
498
+ async connect() {
499
+ return new PrismaNeonAdapter(new neon.Pool(this.config), this.options);
500
+ }
501
+ };
502
+ var PrismaNeonHTTPAdapter = class extends NeonQueryable {
503
+ client;
501
504
  constructor(client) {
502
505
  super();
503
- __publicField(this, "client");
504
506
  this.client = client.query ?? client;
505
507
  }
506
508
  executeScript(_script) {
507
509
  throw new Error("Not implemented yet");
508
510
  }
511
+ async startTransaction() {
512
+ return Promise.reject(new Error("Transactions are not supported in HTTP mode"));
513
+ }
509
514
  async performIO(query) {
510
515
  const { sql, args: values } = query;
511
516
  return await this.client(sql, values, {
@@ -527,13 +532,21 @@ var PrismaNeonHTTP = class extends NeonQueryable {
527
532
  // https://github.com/neondatabase/serverless/pull/110#issuecomment-2458992991
528
533
  });
529
534
  }
530
- transactionContext() {
531
- return Promise.reject(new Error("Transactions are not supported in HTTP mode"));
532
- }
533
535
  async dispose() {
534
536
  }
535
537
  };
538
+ var PrismaNeonHTTPAdapterFactory = class {
539
+ constructor(connectionString, options) {
540
+ this.connectionString = connectionString;
541
+ this.options = options;
542
+ }
543
+ provider = "postgres";
544
+ adapterName = name;
545
+ async connect() {
546
+ return new PrismaNeonHTTPAdapter(neon.neon(this.connectionString, this.options));
547
+ }
548
+ };
536
549
  export {
537
- PrismaNeon,
538
- PrismaNeonHTTP
550
+ PrismaNeonAdapterFactory as PrismaNeon,
551
+ PrismaNeonHTTPAdapterFactory as PrismaNeonHTTP
539
552
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-neon",
3
- "version": "6.6.0-dev.7",
3
+ "version": "6.6.0-dev.71",
4
4
  "description": "Prisma's driver adapter for \"@neondatabase/serverless\"",
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.7"
34
+ "postgres-array": "3.0.4",
35
+ "@prisma/driver-adapter-utils": "6.6.0-dev.71"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@neondatabase/serverless": "0.10.2",