fix batch upsert

This commit is contained in:
Rizky
2024-10-09 14:16:03 +07:00
parent 0825b55d82
commit 4bf174a09c
3 changed files with 12 additions and 2 deletions
+9 -1
View File
@@ -194,7 +194,8 @@ export const execQuery = async (args: DBArg, prisma: any) => {
const marker = {} as any;
for (const row of data) {
const found = existing.find((item, idx) => {
let found = existing.find((item, idx) => {
for (const pk of pks) {
if (item[pk.name] !== row[pk.name]) return false;
}
@@ -202,6 +203,12 @@ export const execQuery = async (args: DBArg, prisma: any) => {
return true;
});
if (!found) {
for (const pk of pks) {
if (row[pk.name]) found = row;
}
}
for (const [k, v] of Object.entries(row) as any) {
const rel = rels[k];
if (rel) {
@@ -291,6 +298,7 @@ export const execQuery = async (args: DBArg, prisma: any) => {
}
}
if (updates.length > 0) {
for (const row of updates) {
const where = {} as any;