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
+13 -3
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 });
}
}
}