fix batch upsert
This commit is contained in:
+9
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user