From aadb345fc50d4019461f0dcc35f89a68e5d59468 Mon Sep 17 00:00:00 2001 From: Rizky Date: Sat, 27 Apr 2024 08:48:21 +0700 Subject: [PATCH] fix query --- pkgs/utils/query.ts | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/pkgs/utils/query.ts b/pkgs/utils/query.ts index 6c58f31..4cf0366 100644 --- a/pkgs/utils/query.ts +++ b/pkgs/utils/query.ts @@ -197,42 +197,33 @@ export const execQuery = async (args: DBArg, prisma: any) => { if (tableInstance) { if (action === "query" && table.startsWith("$query")) { - try { - const gzip = params as unknown as string; + const gzip = params as unknown as string; - const u8 = new Uint8Array([...atob(gzip)].map((c) => c.charCodeAt(0))); - const json = JSON.parse((await gunzipAsync(u8)).toString("utf8")); + const u8 = new Uint8Array([...atob(gzip)].map((c) => c.charCodeAt(0))); + const json = JSON.parse((await gunzipAsync(u8)).toString("utf8")); - if (table === "$queryRawUnsafe") { - return await tableInstance.bind(prisma)(...json); - } - - if (Array.isArray(json)) { - const q = json.shift(); - return await tableInstance.bind(prisma)(Prisma.sql(q, ...json)); - } - - return []; - } catch (e) { - console.log(e); - return e; + if (table === "$queryRawUnsafe") { + return await tableInstance.bind(prisma)(...json); } + + if (Array.isArray(json)) { + const q = json.shift(); + return await tableInstance.bind(prisma)(Prisma.sql(q, ...json)); + } + + return []; } const method = tableInstance[action]; if (method) { - try { - const result = await method(...params); + const result = await method(...params); - if (!result) { - return JSON.stringify(result); - } - - return result; - } catch (e: any) { - throw new Error(e.message); + if (!result) { + return JSON.stringify(result); } + + return result; } } };