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