From 15d725701d2b77c1542d6e075f305b21bfa8cf3e Mon Sep 17 00:00:00 2001 From: Rizky Date: Fri, 10 May 2024 19:50:09 +0700 Subject: [PATCH] fix query upsert --- pkgs/utils/query.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkgs/utils/query.ts b/pkgs/utils/query.ts index e3d066d..147c046 100644 --- a/pkgs/utils/query.ts +++ b/pkgs/utils/query.ts @@ -70,9 +70,9 @@ export const execQuery = async (args: DBArg, prisma: any) => { }); if (found) { - updates.push({...row, ...where}); + updates.push({ ...row, ...where }); } else { - inserts.push({...row, ...where}); + inserts.push({ ...row, ...where }); } } @@ -98,7 +98,9 @@ export const execQuery = async (args: DBArg, prisma: any) => { const where = {} as any; for (const pk of pks) { where[pk.name] = item[pk.name]; + delete item[pk.name]; } + transactions.push( prisma[table].update({ data: item, where }) );