fix batch upsert
This commit is contained in:
parent
0825b55d82
commit
4bf174a09c
|
|
@ -8,7 +8,8 @@ export const _ = {
|
|||
url: "/_dbs/*",
|
||||
raw: true,
|
||||
async api() {
|
||||
const { req, res } = apiContext(this);
|
||||
const ctx = apiContext(this);
|
||||
const { req, res } = ctx;
|
||||
if (typeof g.db !== "undefined") {
|
||||
if (req.params._ === "check") {
|
||||
return { mode: "encrypted" };
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import { prepareAPITypes } from "./server/prep-api-ts";
|
|||
import { config } from "./utils/config";
|
||||
import { g } from "./utils/global";
|
||||
import { createLogger } from "./utils/logger";
|
||||
import { execQuery } from "utils/query";
|
||||
|
||||
if (process.argv[process.argv.length - 1] === "skip_types") {
|
||||
g.skip_build_types = true;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue