@prisma/adapter-pg 6.15.0-dev.1 → 6.15.0-dev.11

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,51 @@ 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 formatTime(arg);
376
+ case "DATE":
377
+ return formatDate(arg);
378
+ default:
379
+ return formatDateTime(arg);
372
380
  }
373
381
  }
374
- return values;
382
+ if (typeof arg === "string" && argType.scalarType === "bytes") {
383
+ return Buffer.from(arg, "base64");
384
+ }
385
+ if (Array.isArray(arg) && argType.scalarType === "bytes") {
386
+ return Buffer.from(arg);
387
+ }
388
+ if (ArrayBuffer.isView(arg)) {
389
+ return Buffer.from(arg.buffer, arg.byteOffset, arg.byteLength);
390
+ }
391
+ return arg;
392
+ }
393
+ function formatDateTime(date) {
394
+ const pad = (n, z = 2) => String(n).padStart(z, "0");
395
+ const ms = date.getUTCMilliseconds();
396
+ return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate()) + " " + pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
397
+ }
398
+ function formatDate(date) {
399
+ const pad = (n, z = 2) => String(n).padStart(z, "0");
400
+ return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate());
401
+ }
402
+ function formatTime(date) {
403
+ const pad = (n, z = 2) => String(n).padStart(z, "0");
404
+ const ms = date.getUTCMilliseconds();
405
+ return pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
375
406
  }
376
407
 
377
408
  // src/errors.ts
@@ -602,12 +633,13 @@ var PgQueryable = class {
602
633
  * marked as unhealthy.
603
634
  */
604
635
  async performIO(query) {
605
- const { sql, args: values } = query;
636
+ const { sql, args } = query;
637
+ const values = args.map((arg, i) => mapArg(arg, query.argTypes[i]));
606
638
  try {
607
639
  const result = await this.client.query(
608
640
  {
609
641
  text: sql,
610
- values: fixArrayBufferValues(values),
642
+ values,
611
643
  rowMode: "array",
612
644
  types: {
613
645
  // This is the error expected:
@@ -630,7 +662,7 @@ var PgQueryable = class {
630
662
  }
631
663
  }
632
664
  },
633
- fixArrayBufferValues(values)
665
+ values
634
666
  );
635
667
  return result;
636
668
  } catch (e) {
@@ -669,6 +701,10 @@ var PrismaPgAdapter = class extends PgQueryable {
669
701
  const tag = "[js::startTransaction]";
670
702
  debug("%s options: %O", tag, options);
671
703
  const conn = await this.client.connect().catch((error) => this.onError(error));
704
+ conn.on("error", (err) => {
705
+ debug(`Error from pool connection: ${err.message} %O`, err);
706
+ this.options?.onConnectionError?.(err);
707
+ });
672
708
  try {
673
709
  const tx = new PgTransaction(conn, options);
674
710
  await tx.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
package/dist/index.mjs CHANGED
@@ -322,20 +322,51 @@ 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 formatTime(arg);
340
+ case "DATE":
341
+ return formatDate(arg);
342
+ default:
343
+ return formatDateTime(arg);
336
344
  }
337
345
  }
338
- return values;
346
+ if (typeof arg === "string" && argType.scalarType === "bytes") {
347
+ return Buffer.from(arg, "base64");
348
+ }
349
+ if (Array.isArray(arg) && argType.scalarType === "bytes") {
350
+ return Buffer.from(arg);
351
+ }
352
+ if (ArrayBuffer.isView(arg)) {
353
+ return Buffer.from(arg.buffer, arg.byteOffset, arg.byteLength);
354
+ }
355
+ return arg;
356
+ }
357
+ function formatDateTime(date) {
358
+ const pad = (n, z = 2) => String(n).padStart(z, "0");
359
+ const ms = date.getUTCMilliseconds();
360
+ return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate()) + " " + pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
361
+ }
362
+ function formatDate(date) {
363
+ const pad = (n, z = 2) => String(n).padStart(z, "0");
364
+ return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate());
365
+ }
366
+ function formatTime(date) {
367
+ const pad = (n, z = 2) => String(n).padStart(z, "0");
368
+ const ms = date.getUTCMilliseconds();
369
+ return pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + (ms ? "." + String(ms).padStart(3, "0") : "");
339
370
  }
340
371
 
341
372
  // src/errors.ts
@@ -566,12 +597,13 @@ var PgQueryable = class {
566
597
  * marked as unhealthy.
567
598
  */
568
599
  async performIO(query) {
569
- const { sql, args: values } = query;
600
+ const { sql, args } = query;
601
+ const values = args.map((arg, i) => mapArg(arg, query.argTypes[i]));
570
602
  try {
571
603
  const result = await this.client.query(
572
604
  {
573
605
  text: sql,
574
- values: fixArrayBufferValues(values),
606
+ values,
575
607
  rowMode: "array",
576
608
  types: {
577
609
  // This is the error expected:
@@ -594,7 +626,7 @@ var PgQueryable = class {
594
626
  }
595
627
  }
596
628
  },
597
- fixArrayBufferValues(values)
629
+ values
598
630
  );
599
631
  return result;
600
632
  } catch (e) {
@@ -633,6 +665,10 @@ var PrismaPgAdapter = class extends PgQueryable {
633
665
  const tag = "[js::startTransaction]";
634
666
  debug("%s options: %O", tag, options);
635
667
  const conn = await this.client.connect().catch((error) => this.onError(error));
668
+ conn.on("error", (err) => {
669
+ debug(`Error from pool connection: ${err.message} %O`, err);
670
+ this.options?.onConnectionError?.(err);
671
+ });
636
672
  try {
637
673
  const tx = new PgTransaction(conn, options);
638
674
  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.1",
3
+ "version": "6.15.0-dev.11",
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.1"
36
+ "@prisma/driver-adapter-utils": "6.15.0-dev.11"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@swc/core": "1.11.5",