@onreza/prisma-adapter-bun 0.4.2 → 0.4.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/conversion.ts +23 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onreza/prisma-adapter-bun",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "Prisma 7+ driver adapter for Bun.sql — use Bun's built-in PostgreSQL client instead of pg",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/conversion.ts CHANGED
@@ -376,6 +376,18 @@ export function toPgArrayLiteral(arr: unknown[]): string {
376
376
 
377
377
  // --- Argument mapping (input parameters) ---
378
378
 
379
+ function formatDateArg(date: Date, dbType: string | undefined): string {
380
+ switch (dbType) {
381
+ case "TIME":
382
+ case "TIMETZ":
383
+ return formatTime(date);
384
+ case "DATE":
385
+ return formatDate(date);
386
+ default:
387
+ return formatDateTime(date);
388
+ }
389
+ }
390
+
379
391
  export function mapArg(arg: unknown, argType: ArgType): unknown {
380
392
  if (arg === null || arg === undefined) return null;
381
393
 
@@ -386,15 +398,17 @@ export function mapArg(arg: unknown, argType: ArgType): unknown {
386
398
 
387
399
  const value = typeof arg === "string" && argType.scalarType === "datetime" ? new Date(arg) : arg;
388
400
 
389
- if (value instanceof Date) {
390
- switch (argType.dbType) {
391
- case "TIME":
392
- case "TIMETZ":
393
- return formatTime(value);
394
- case "DATE":
395
- return formatDate(value);
396
- default:
397
- return formatDateTime(value);
401
+ if (value instanceof Date) return formatDateArg(value, argType.dbType);
402
+
403
+ // Prisma sends JSON as pre-stringified strings (e.g. '{"role":"admin"}').
404
+ // Bun.sql's unsafe() serializes parameters via JSON.stringify, which would
405
+ // double-stringify a JSON string. Parse it back to a JS object so Bun.sql
406
+ // can serialize it correctly as a single JSON value.
407
+ if (typeof value === "string" && argType.scalarType === "json") {
408
+ try {
409
+ return JSON.parse(value);
410
+ } catch {
411
+ return value;
398
412
  }
399
413
  }
400
414