add mode in batch upsert
This commit is contained in:
parent
22134b76db
commit
594b37371b
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
@ -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,11 +72,19 @@ export const execQuery = async (args: DBArg, prisma: any) => {
|
|||
return true;
|
||||
});
|
||||
|
||||
if (mode === "field") {
|
||||
if (found) {
|
||||
updates.push({ ...row, ...where });
|
||||
} else {
|
||||
inserts.push({ ...row, ...where });
|
||||
}
|
||||
} else {
|
||||
if (found) {
|
||||
updates.push({ ...row });
|
||||
} else {
|
||||
inserts.push({ ...row });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (exists_idx.size !== existing.length) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue