add mode in batch upsert

This commit is contained in:
rizrmd 2024-06-04 13:07:03 +07:00
parent 22134b76db
commit 594b37371b
3 changed files with 19 additions and 9 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -1,22 +1,22 @@
{
"name": "pkgs",
"dependencies": {
"@mrleebo/prisma-ast": "^0.10.1",
"@surfy/multipart-parser": "^1.0.2",
"@swc/core": "^1.3.91",
"@swc/core": "^1.5.7",
"@types/mime": "^3.0.2",
"@types/unzipper": "^0.10.7",
"execa": "^8.0.1",
"rambda": "^9.1.0",
"fs-jetpack": "^5.1.0",
"@mrleebo/prisma-ast": "^0.10.1",
"lmdb": "^2.8.5",
"mime": "^3.0.0",
"parse-multipart-data": "^1.5.0",
"pino": "^8.15.3",
"pino-pretty": "^10.2.0",
"radix3": "^1.1.0",
"rambda": "^9.1.0",
"sharp": "^0.33.2",
"typescript": "^5.2.2",
"unzipper": "^0.10.14",
"parse-multipart-data": "^1.5.0",
"sharp": "^0.33.2"
"unzipper": "^0.10.14"
}
}

View File

@ -21,10 +21,12 @@ export const execQuery = async (args: DBArg, prisma: any) => {
table: string;
where: any;
data: any[];
mode: "field" | "relation";
};
};
if (arg) {
const { table, where, data } = arg;
const mode = arg.mode || "field";
if (table && where && data) {
const transactions = [];
@ -70,10 +72,18 @@ export const execQuery = async (args: DBArg, prisma: any) => {
return true;
});
if (found) {
updates.push({ ...row, ...where });
if (mode === "field") {
if (found) {
updates.push({ ...row, ...where });
} else {
inserts.push({ ...row, ...where });
}
} else {
inserts.push({ ...row, ...where });
if (found) {
updates.push({ ...row });
} else {
inserts.push({ ...row });
}
}
}