@prisma/adapter-neon 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,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
@@ -30,8 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- PrismaNeon: () => PrismaNeon,
34
- PrismaNeonHTTP: () => PrismaNeonHTTP
33
+ PrismaNeon: () => PrismaNeonAdapterFactory,
34
+ PrismaNeonHTTP: () => PrismaNeonHTTPAdapterFactory
35
35
  });
36
36
  module.exports = __toCommonJS(index_exports);
37
37
 
@@ -481,29 +481,8 @@ var NeonTransaction = class extends NeonWsQueryable {
481
481
  this.client.release();
482
482
  }
483
483
  };
484
- var NeonTransactionContext = class extends NeonWsQueryable {
485
- constructor(conn) {
486
- super(conn);
487
- this.conn = conn;
488
- }
489
- async startTransaction() {
490
- const options = {
491
- usePhantomQuery: false
492
- };
493
- const tag = "[js::startTransaction]";
494
- debug("%s options: %O", tag, options);
495
- return new NeonTransaction(this.conn, options);
496
- }
497
- };
498
- var PrismaNeon = class extends NeonWsQueryable {
484
+ var PrismaNeonAdapter = class extends NeonWsQueryable {
499
485
  constructor(pool, options) {
500
- if (!(pool instanceof neon.Pool)) {
501
- throw new TypeError(`PrismaNeon must be initialized with an instance of Pool:
502
- import { Pool } from '@neondatabase/serverless'
503
- const pool = new Pool({ connectionString: url })
504
- const adapter = new PrismaNeon(pool)
505
- `);
506
- }
507
486
  super(pool);
508
487
  this.options = options;
509
488
  }
@@ -511,15 +490,34 @@ const adapter = new PrismaNeon(pool)
511
490
  executeScript(_script) {
512
491
  throw new Error("Not implemented yet");
513
492
  }
493
+ async startTransaction(isolationLevel) {
494
+ const options = {
495
+ usePhantomQuery: false
496
+ };
497
+ const tag = "[js::startTransaction]";
498
+ debug("%s options: %O", tag, options);
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;
514
+ }
515
+ }
514
516
  getConnectionInfo() {
515
517
  return {
516
518
  schemaName: this.options?.schema
517
519
  };
518
520
  }
519
- async transactionContext() {
520
- const conn = await this.client.connect();
521
- return new NeonTransactionContext(conn);
522
- }
523
521
  async dispose() {
524
522
  if (this.isRunning) {
525
523
  await this.client.end();
@@ -527,7 +525,18 @@ const adapter = new PrismaNeon(pool)
527
525
  }
528
526
  }
529
527
  };
530
- 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 {
531
540
  client;
532
541
  constructor(client) {
533
542
  super();
@@ -536,6 +545,9 @@ var PrismaNeonHTTP = class extends NeonQueryable {
536
545
  executeScript(_script) {
537
546
  throw new Error("Not implemented yet");
538
547
  }
548
+ async startTransaction() {
549
+ return Promise.reject(new Error("Transactions are not supported in HTTP mode"));
550
+ }
539
551
  async performIO(query) {
540
552
  const { sql, args: values } = query;
541
553
  return await this.client(sql, values, {
@@ -557,12 +569,20 @@ var PrismaNeonHTTP = class extends NeonQueryable {
557
569
  // https://github.com/neondatabase/serverless/pull/110#issuecomment-2458992991
558
570
  });
559
571
  }
560
- transactionContext() {
561
- return Promise.reject(new Error("Transactions are not supported in HTTP mode"));
562
- }
563
572
  async dispose() {
564
573
  }
565
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
+ };
566
586
  // Annotate the CommonJS export names for ESM import in node:
567
587
  0 && (module.exports = {
568
588
  PrismaNeon,
package/dist/index.mjs CHANGED
@@ -444,29 +444,8 @@ var NeonTransaction = class extends NeonWsQueryable {
444
444
  this.client.release();
445
445
  }
446
446
  };
447
- var NeonTransactionContext = class extends NeonWsQueryable {
448
- constructor(conn) {
449
- super(conn);
450
- this.conn = conn;
451
- }
452
- async startTransaction() {
453
- const options = {
454
- usePhantomQuery: false
455
- };
456
- const tag = "[js::startTransaction]";
457
- debug("%s options: %O", tag, options);
458
- return new NeonTransaction(this.conn, options);
459
- }
460
- };
461
- var PrismaNeon = class extends NeonWsQueryable {
447
+ var PrismaNeonAdapter = class extends NeonWsQueryable {
462
448
  constructor(pool, options) {
463
- if (!(pool instanceof neon.Pool)) {
464
- throw new TypeError(`PrismaNeon must be initialized with an instance of Pool:
465
- import { Pool } from '@neondatabase/serverless'
466
- const pool = new Pool({ connectionString: url })
467
- const adapter = new PrismaNeon(pool)
468
- `);
469
- }
470
449
  super(pool);
471
450
  this.options = options;
472
451
  }
@@ -474,15 +453,34 @@ const adapter = new PrismaNeon(pool)
474
453
  executeScript(_script) {
475
454
  throw new Error("Not implemented yet");
476
455
  }
456
+ async startTransaction(isolationLevel) {
457
+ const options = {
458
+ usePhantomQuery: false
459
+ };
460
+ const tag = "[js::startTransaction]";
461
+ debug("%s options: %O", tag, options);
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;
477
+ }
478
+ }
477
479
  getConnectionInfo() {
478
480
  return {
479
481
  schemaName: this.options?.schema
480
482
  };
481
483
  }
482
- async transactionContext() {
483
- const conn = await this.client.connect();
484
- return new NeonTransactionContext(conn);
485
- }
486
484
  async dispose() {
487
485
  if (this.isRunning) {
488
486
  await this.client.end();
@@ -490,7 +488,18 @@ const adapter = new PrismaNeon(pool)
490
488
  }
491
489
  }
492
490
  };
493
- 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 {
494
503
  client;
495
504
  constructor(client) {
496
505
  super();
@@ -499,6 +508,9 @@ var PrismaNeonHTTP = class extends NeonQueryable {
499
508
  executeScript(_script) {
500
509
  throw new Error("Not implemented yet");
501
510
  }
511
+ async startTransaction() {
512
+ return Promise.reject(new Error("Transactions are not supported in HTTP mode"));
513
+ }
502
514
  async performIO(query) {
503
515
  const { sql, args: values } = query;
504
516
  return await this.client(sql, values, {
@@ -520,13 +532,21 @@ var PrismaNeonHTTP = class extends NeonQueryable {
520
532
  // https://github.com/neondatabase/serverless/pull/110#issuecomment-2458992991
521
533
  });
522
534
  }
523
- transactionContext() {
524
- return Promise.reject(new Error("Transactions are not supported in HTTP mode"));
525
- }
526
535
  async dispose() {
527
536
  }
528
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
+ };
529
549
  export {
530
- PrismaNeon,
531
- PrismaNeonHTTP
550
+ PrismaNeonAdapterFactory as PrismaNeon,
551
+ PrismaNeonHTTPAdapterFactory as PrismaNeonHTTP
532
552
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-neon",
3
- "version": "6.6.0-dev.32",
3
+ "version": "6.6.0-dev.34",
4
4
  "description": "Prisma's driver adapter for \"@neondatabase/serverless\"",
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
  "@neondatabase/serverless": "0.10.2",