pqb 0.31.5 → 0.31.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +22 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4385,27 +4385,20 @@ const pushInsertSql = (ctx, q, query, quotedAs) => {
|
|
|
4385
4385
|
if (merge) {
|
|
4386
4386
|
if (typeof merge === "string") {
|
|
4387
4387
|
const name = ((_c = shape[merge]) == null ? void 0 : _c.data.name) || merge;
|
|
4388
|
-
sql = `"${name}" = excluded."${name}"`;
|
|
4388
|
+
sql = `DO UPDATE SET "${name}" = excluded."${name}"`;
|
|
4389
4389
|
} else if ("except" in merge) {
|
|
4390
|
-
|
|
4391
|
-
const except = orchidCore.toArray(merge.except);
|
|
4392
|
-
for (let i = 0; i < columns.length; i++) {
|
|
4393
|
-
if (!except.includes(columns[i])) {
|
|
4394
|
-
notExcluded.push(quotedColumns[i]);
|
|
4395
|
-
}
|
|
4396
|
-
}
|
|
4397
|
-
sql = mergeColumnsSql(notExcluded);
|
|
4390
|
+
sql = mergeColumnsSql(columns, quotedColumns, target, merge.except);
|
|
4398
4391
|
} else {
|
|
4399
|
-
sql = merge.reduce((sql2, item, i) => {
|
|
4392
|
+
sql = `DO UPDATE SET ${merge.reduce((sql2, item, i) => {
|
|
4400
4393
|
var _a2;
|
|
4401
4394
|
const name = ((_a2 = shape[item]) == null ? void 0 : _a2.data.name) || item;
|
|
4402
4395
|
return sql2 + (i ? ", " : "") + `"${name}" = excluded."${name}"`;
|
|
4403
|
-
}, "")
|
|
4396
|
+
}, "")}`;
|
|
4404
4397
|
}
|
|
4405
4398
|
} else {
|
|
4406
|
-
sql = mergeColumnsSql(quotedColumns);
|
|
4399
|
+
sql = mergeColumnsSql(columns, quotedColumns, target);
|
|
4407
4400
|
}
|
|
4408
|
-
ctx.sql.push(
|
|
4401
|
+
ctx.sql.push(sql);
|
|
4409
4402
|
} else if (query.onConflict.set) {
|
|
4410
4403
|
let sql;
|
|
4411
4404
|
const { set } = query.onConflict;
|
|
@@ -4431,8 +4424,22 @@ const pushInsertSql = (ctx, q, query, quotedAs) => {
|
|
|
4431
4424
|
pushWhereStatementSql(ctx, q, query, quotedAs);
|
|
4432
4425
|
return pushReturningSql(ctx, q, query, quotedAs, query.afterCreateSelect);
|
|
4433
4426
|
};
|
|
4434
|
-
const mergeColumnsSql = (quotedColumns2) => {
|
|
4435
|
-
|
|
4427
|
+
const mergeColumnsSql = (columns, quotedColumns2, target, except) => {
|
|
4428
|
+
const notExcluded = [];
|
|
4429
|
+
const exclude = typeof target === "string" ? [target] : Array.isArray(target) ? [...target] : [];
|
|
4430
|
+
if (except) {
|
|
4431
|
+
if (typeof except === "string") {
|
|
4432
|
+
exclude.push(except);
|
|
4433
|
+
} else {
|
|
4434
|
+
exclude.push(...except);
|
|
4435
|
+
}
|
|
4436
|
+
}
|
|
4437
|
+
for (let i = 0; i < columns.length; i++) {
|
|
4438
|
+
if (!exclude.includes(columns[i])) {
|
|
4439
|
+
notExcluded.push(quotedColumns2[i]);
|
|
4440
|
+
}
|
|
4441
|
+
}
|
|
4442
|
+
return notExcluded.length ? `DO UPDATE SET ${notExcluded.map((column) => `${column} = excluded.${column}`).join(", ")}` : "DO NOTHING";
|
|
4436
4443
|
};
|
|
4437
4444
|
const encodeRow = (ctx, q, QueryClass, row, runtimeDefaults, quotedAs) => {
|
|
4438
4445
|
const arr = row.map((value) => {
|