pqb 0.47.1 → 0.47.3

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
@@ -3102,13 +3102,15 @@ const processComputedResult = (query, result) => {
3102
3102
  };
3103
3103
  const processComputedBatches = (query, batches, originalReturnType, returnType, tempColumns, renames, key) => {
3104
3104
  let promises;
3105
- for (const key2 in query.selectedComputeds) {
3106
- const computed = query.selectedComputeds[key2];
3105
+ const plainValue = originalReturnType === "value" || originalReturnType === "valueOrThrow";
3106
+ for (const computedKey in query.selectedComputeds) {
3107
+ const setAsKey = plainValue ? key : computedKey;
3108
+ const computed = query.selectedComputeds[computedKey];
3107
3109
  if (computed.kind === "one") {
3108
3110
  for (const { data } of batches) {
3109
3111
  for (const record of data) {
3110
3112
  if (record) {
3111
- record[key2] = computed.fn(record);
3113
+ record[setAsKey] = computed.fn(record);
3112
3114
  }
3113
3115
  }
3114
3116
  }
@@ -3131,11 +3133,11 @@ const processComputedBatches = (query, batches, originalReturnType, returnType,
3131
3133
  }
3132
3134
  const res = computed.fn(present);
3133
3135
  if (Array.isArray(res)) {
3134
- saveBatchComputed(key2, data, res, blanks);
3136
+ saveBatchComputed(setAsKey, data, res, blanks);
3135
3137
  } else {
3136
3138
  (promises ?? (promises = [])).push(
3137
3139
  res.then(
3138
- (res2) => saveBatchComputed(key2, data, res2, blanks)
3140
+ (res2) => saveBatchComputed(setAsKey, data, res2, blanks)
3139
3141
  )
3140
3142
  );
3141
3143
  }
@@ -4701,7 +4703,11 @@ const mergeColumnsSql = (columns, quotedColumns2, target, except) => {
4701
4703
  notExcluded.push(quotedColumns2[i]);
4702
4704
  }
4703
4705
  }
4704
- return notExcluded.length ? `DO UPDATE SET ${notExcluded.map((column) => `${column} = excluded.${column}`).join(", ")}` : "DO NOTHING";
4706
+ return notExcluded.length ? `DO UPDATE SET ${notExcluded.map((column) => `${column} = excluded.${column}`).join(", ")}` : (
4707
+ // update whatever is the first column because DO NOTHING prevents RETURNING,
4708
+ // and we might want to return data from the insert
4709
+ `DO UPDATE SET ${quotedColumns2[0]} = excluded.${quotedColumns2[0]}`
4710
+ );
4705
4711
  };
4706
4712
  const encodeRow = (ctx, values, q, QueryClass, row, runtimeDefaults, quotedAs) => {
4707
4713
  const arr = row.map((value) => {