This commit is contained in:
Rizky 2024-04-18 15:10:55 +07:00
parent 3d0c77f41f
commit 631f69e6fc
1 changed files with 16 additions and 4 deletions

View File

@ -1,3 +1,5 @@
import { Prisma } from "../../../app/db/db";
import { gunzipAsync } from "./diff/diff";
export type DBArg = { export type DBArg = {
db: string; db: string;
@ -14,10 +16,20 @@ export const execQuery = async (args: DBArg, prisma: any) => {
if (tableInstance) { if (tableInstance) {
if (action === "query" && table.startsWith("$query")) { if (action === "query" && table.startsWith("$query")) {
try { try {
const q = params.shift(); const gzip = params as unknown as string;
q.sql = true;
Object.freeze(q); if (typeof gzip === "string") {
return await tableInstance.bind(prisma)(q, ...params); const u8 = new Uint8Array(
[...atob(gzip)].map((c) => c.charCodeAt(0))
);
const json = JSON.parse((await gunzipAsync(u8)).toString("utf8"));
if (Array.isArray(json)) {
const q = json.shift();
return await tableInstance.bind(prisma)(Prisma.sql(q, ...json));
}
}
} catch (e) { } catch (e) {
console.log(e); console.log(e);
return e; return e;