@prisma/adapter-pg 6.15.0-dev.3 → 6.15.0-dev.5

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
@@ -58,6 +58,7 @@ declare type PrismaPgOptions = {
58
58
  schema?: string;
59
59
  disposeExternalPool?: boolean;
60
60
  onPoolError?: (err: Error) => void;
61
+ onConnectionError?: (err: Error) => void;
61
62
  };
62
63
 
63
64
  declare type StdClient = pg.Pool;
package/dist/index.d.ts CHANGED
@@ -58,6 +58,7 @@ declare type PrismaPgOptions = {
58
58
  schema?: string;
59
59
  disposeExternalPool?: boolean;
60
60
  onPoolError?: (err: Error) => void;
61
+ onConnectionError?: (err: Error) => void;
61
62
  };
62
63
 
63
64
  declare type StdClient = pg.Pool;
package/dist/index.js CHANGED
@@ -358,20 +358,35 @@ var customParsers = {
358
358
  [ArrayColumnType.VARBIT_ARRAY]: normalize_array(normalizeBit),
359
359
  [ArrayColumnType.XML_ARRAY]: normalize_array(normalize_xml)
360
360
  };
361
- function fixArrayBufferValues(values) {
362
- for (let i = 0; i < values.length; i++) {
363
- const list = values[i];
364
- if (!Array.isArray(list)) {
365
- continue;
366
- }
367
- for (let j = 0; j < list.length; j++) {
368
- const listItem = list[j];
369
- if (ArrayBuffer.isView(listItem)) {
370
- list[j] = Buffer.from(listItem.buffer, listItem.byteOffset, listItem.byteLength);
371
- }
361
+ function mapArg(arg, argType) {
362
+ if (arg === null) {
363
+ return null;
364
+ }
365
+ if (Array.isArray(arg) && argType.arity === "list") {
366
+ return arg.map((value) => mapArg(value, argType));
367
+ }
368
+ if (typeof arg === "string" && argType.scalarType === "datetime") {
369
+ arg = new Date(arg);
370
+ }
371
+ if (arg instanceof Date) {
372
+ switch (argType.dbType) {
373
+ case "TIME":
374
+ case "TIMETZ":
375
+ return arg.toISOString().split("T")[1];
376
+ default:
377
+ return arg.toISOString();
372
378
  }
373
379
  }
374
- return values;
380
+ if (typeof arg === "string" && argType.scalarType === "bytes") {
381
+ return Buffer.from(arg, "base64");
382
+ }
383
+ if (Array.isArray(arg) && argType.scalarType === "bytes") {
384
+ return Buffer.from(arg);
385
+ }
386
+ if (ArrayBuffer.isView(arg)) {
387
+ return Buffer.from(arg.buffer, arg.byteOffset, arg.byteLength);
388
+ }
389
+ return arg;
375
390
  }
376
391
 
377
392
  // src/errors.ts
@@ -602,12 +617,13 @@ var PgQueryable = class {
602
617
  * marked as unhealthy.
603
618
  */
604
619
  async performIO(query) {
605
- const { sql, args: values } = query;
620
+ const { sql, args } = query;
621
+ const values = args.map((arg, i) => mapArg(arg, query.argTypes[i]));
606
622
  try {
607
623
  const result = await this.client.query(
608
624
  {
609
625
  text: sql,
610
- values: fixArrayBufferValues(values),
626
+ values,
611
627
  rowMode: "array",
612
628
  types: {
613
629
  // This is the error expected:
@@ -630,7 +646,7 @@ var PgQueryable = class {
630
646
  }
631
647
  }
632
648
  },
633
- fixArrayBufferValues(values)
649
+ values
634
650
  );
635
651
  return result;
636
652
  } catch (e) {
@@ -669,6 +685,10 @@ var PrismaPgAdapter = class extends PgQueryable {
669
685
  const tag = "[js::startTransaction]";
670
686
  debug("%s options: %O", tag, options);
671
687
  const conn = await this.client.connect().catch((error) => this.onError(error));
688
+ conn.on("error", (err) => {
689
+ debug(`Error from pool connection: ${err.message} %O`, err);
690
+ this.options?.onConnectionError?.(err);
691
+ });
672
692
  try {
673
693
  const tx = new PgTransaction(conn, options);
674
694
  await tx.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
package/dist/index.mjs CHANGED
@@ -322,20 +322,35 @@ var customParsers = {
322
322
  [ArrayColumnType.VARBIT_ARRAY]: normalize_array(normalizeBit),
323
323
  [ArrayColumnType.XML_ARRAY]: normalize_array(normalize_xml)
324
324
  };
325
- function fixArrayBufferValues(values) {
326
- for (let i = 0; i < values.length; i++) {
327
- const list = values[i];
328
- if (!Array.isArray(list)) {
329
- continue;
330
- }
331
- for (let j = 0; j < list.length; j++) {
332
- const listItem = list[j];
333
- if (ArrayBuffer.isView(listItem)) {
334
- list[j] = Buffer.from(listItem.buffer, listItem.byteOffset, listItem.byteLength);
335
- }
325
+ function mapArg(arg, argType) {
326
+ if (arg === null) {
327
+ return null;
328
+ }
329
+ if (Array.isArray(arg) && argType.arity === "list") {
330
+ return arg.map((value) => mapArg(value, argType));
331
+ }
332
+ if (typeof arg === "string" && argType.scalarType === "datetime") {
333
+ arg = new Date(arg);
334
+ }
335
+ if (arg instanceof Date) {
336
+ switch (argType.dbType) {
337
+ case "TIME":
338
+ case "TIMETZ":
339
+ return arg.toISOString().split("T")[1];
340
+ default:
341
+ return arg.toISOString();
336
342
  }
337
343
  }
338
- return values;
344
+ if (typeof arg === "string" && argType.scalarType === "bytes") {
345
+ return Buffer.from(arg, "base64");
346
+ }
347
+ if (Array.isArray(arg) && argType.scalarType === "bytes") {
348
+ return Buffer.from(arg);
349
+ }
350
+ if (ArrayBuffer.isView(arg)) {
351
+ return Buffer.from(arg.buffer, arg.byteOffset, arg.byteLength);
352
+ }
353
+ return arg;
339
354
  }
340
355
 
341
356
  // src/errors.ts
@@ -566,12 +581,13 @@ var PgQueryable = class {
566
581
  * marked as unhealthy.
567
582
  */
568
583
  async performIO(query) {
569
- const { sql, args: values } = query;
584
+ const { sql, args } = query;
585
+ const values = args.map((arg, i) => mapArg(arg, query.argTypes[i]));
570
586
  try {
571
587
  const result = await this.client.query(
572
588
  {
573
589
  text: sql,
574
- values: fixArrayBufferValues(values),
590
+ values,
575
591
  rowMode: "array",
576
592
  types: {
577
593
  // This is the error expected:
@@ -594,7 +610,7 @@ var PgQueryable = class {
594
610
  }
595
611
  }
596
612
  },
597
- fixArrayBufferValues(values)
613
+ values
598
614
  );
599
615
  return result;
600
616
  } catch (e) {
@@ -633,6 +649,10 @@ var PrismaPgAdapter = class extends PgQueryable {
633
649
  const tag = "[js::startTransaction]";
634
650
  debug("%s options: %O", tag, options);
635
651
  const conn = await this.client.connect().catch((error) => this.onError(error));
652
+ conn.on("error", (err) => {
653
+ debug(`Error from pool connection: ${err.message} %O`, err);
654
+ this.options?.onConnectionError?.(err);
655
+ });
636
656
  try {
637
657
  const tx = new PgTransaction(conn, options);
638
658
  await tx.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-pg",
3
- "version": "6.15.0-dev.3",
3
+ "version": "6.15.0-dev.5",
4
4
  "description": "Prisma's driver adapter for \"pg\"",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -33,7 +33,7 @@
33
33
  "dependencies": {
34
34
  "postgres-array": "3.0.4",
35
35
  "pg": "^8.11.3",
36
- "@prisma/driver-adapter-utils": "6.15.0-dev.3"
36
+ "@prisma/driver-adapter-utils": "6.15.0-dev.5"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@swc/core": "1.11.5",