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.mjs CHANGED
@@ -4383,27 +4383,20 @@ const pushInsertSql = (ctx, q, query, quotedAs) => {
4383
4383
  if (merge) {
4384
4384
  if (typeof merge === "string") {
4385
4385
  const name = ((_c = shape[merge]) == null ? void 0 : _c.data.name) || merge;
4386
- sql = `"${name}" = excluded."${name}"`;
4386
+ sql = `DO UPDATE SET "${name}" = excluded."${name}"`;
4387
4387
  } else if ("except" in merge) {
4388
- const notExcluded = [];
4389
- const except = toArray(merge.except);
4390
- for (let i = 0; i < columns.length; i++) {
4391
- if (!except.includes(columns[i])) {
4392
- notExcluded.push(quotedColumns[i]);
4393
- }
4394
- }
4395
- sql = mergeColumnsSql(notExcluded);
4388
+ sql = mergeColumnsSql(columns, quotedColumns, target, merge.except);
4396
4389
  } else {
4397
- sql = merge.reduce((sql2, item, i) => {
4390
+ sql = `DO UPDATE SET ${merge.reduce((sql2, item, i) => {
4398
4391
  var _a2;
4399
4392
  const name = ((_a2 = shape[item]) == null ? void 0 : _a2.data.name) || item;
4400
4393
  return sql2 + (i ? ", " : "") + `"${name}" = excluded."${name}"`;
4401
- }, "");
4394
+ }, "")}`;
4402
4395
  }
4403
4396
  } else {
4404
- sql = mergeColumnsSql(quotedColumns);
4397
+ sql = mergeColumnsSql(columns, quotedColumns, target);
4405
4398
  }
4406
- ctx.sql.push("DO UPDATE SET", sql);
4399
+ ctx.sql.push(sql);
4407
4400
  } else if (query.onConflict.set) {
4408
4401
  let sql;
4409
4402
  const { set } = query.onConflict;
@@ -4429,8 +4422,22 @@ const pushInsertSql = (ctx, q, query, quotedAs) => {
4429
4422
  pushWhereStatementSql(ctx, q, query, quotedAs);
4430
4423
  return pushReturningSql(ctx, q, query, quotedAs, query.afterCreateSelect);
4431
4424
  };
4432
- const mergeColumnsSql = (quotedColumns2) => {
4433
- return quotedColumns2.map((column) => `${column} = excluded.${column}`).join(", ");
4425
+ const mergeColumnsSql = (columns, quotedColumns2, target, except) => {
4426
+ const notExcluded = [];
4427
+ const exclude = typeof target === "string" ? [target] : Array.isArray(target) ? [...target] : [];
4428
+ if (except) {
4429
+ if (typeof except === "string") {
4430
+ exclude.push(except);
4431
+ } else {
4432
+ exclude.push(...except);
4433
+ }
4434
+ }
4435
+ for (let i = 0; i < columns.length; i++) {
4436
+ if (!exclude.includes(columns[i])) {
4437
+ notExcluded.push(quotedColumns2[i]);
4438
+ }
4439
+ }
4440
+ return notExcluded.length ? `DO UPDATE SET ${notExcluded.map((column) => `${column} = excluded.${column}`).join(", ")}` : "DO NOTHING";
4434
4441
  };
4435
4442
  const encodeRow = (ctx, q, QueryClass, row, runtimeDefaults, quotedAs) => {
4436
4443
  const arr = row.map((value) => {