@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.
- package/package.json +1 -1
- package/src/conversion.ts +23 -9
package/package.json
CHANGED
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
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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
|
|