pqb 0.57.2 → 0.57.4

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
@@ -3756,7 +3756,7 @@ const makeRowToJson = (table, shape, aliasName) => {
3756
3756
  `'${key}', "${table}"."${aliasName && column.data.name || key}"${column.data.jsonCast ? `::${column.data.jsonCast}` : ""}`
3757
3757
  );
3758
3758
  }
3759
- return isSimple ? `row_to_json("${table}".*)` : `CASE WHEN "${table}".* IS NULL THEN NULL ELSE json_build_object(` + list.join(", ") + ") END";
3759
+ return isSimple ? `row_to_json("${table}".*)` : `CASE WHEN to_jsonb("${table}") IS NULL THEN NULL ELSE json_build_object(` + list.join(", ") + ") END";
3760
3760
  };
3761
3761
 
3762
3762
  const pushDistinctSql = (ctx, table, distinct, quotedAs) => {
@@ -6169,6 +6169,15 @@ class Then {
6169
6169
  catch(fn) {
6170
6170
  return this.then(void 0, fn);
6171
6171
  }
6172
+ catchUniqueError(fn) {
6173
+ return this.then(void 0, (err) => {
6174
+ if (err instanceof QueryError && err.isUnique) {
6175
+ fn(err);
6176
+ } else {
6177
+ throw err;
6178
+ }
6179
+ });
6180
+ }
6172
6181
  }
6173
6182
  let queryError = void 0;
6174
6183
  const getThen = function() {
@@ -7600,14 +7609,17 @@ const makeInsertSql = (ctx, q, query, quotedAs, isSubSql) => {
7600
7609
  (column) => `"${shape[column]?.data.name || column}"`
7601
7610
  );
7602
7611
  let runtimeDefaults;
7612
+ let runtimeDefaultColumns;
7603
7613
  if (q.internal.runtimeDefaultColumns) {
7604
7614
  runtimeDefaults = [];
7615
+ runtimeDefaultColumns = [];
7605
7616
  for (const key of q.internal.runtimeDefaultColumns) {
7606
7617
  if (!columns.includes(key)) {
7607
7618
  const column = shape[key];
7608
7619
  columns.push(key);
7609
7620
  quotedColumns.push(`"${column.data.name || key}"`);
7610
7621
  runtimeDefaults.push(column.data.runtimeDefault);
7622
+ runtimeDefaultColumns.push(key);
7611
7623
  }
7612
7624
  }
7613
7625
  }
@@ -7669,7 +7681,10 @@ const makeInsertSql = (ctx, q, query, quotedAs, isSubSql) => {
7669
7681
  const name = shape[merge]?.data.name || merge;
7670
7682
  sql = `DO UPDATE SET "${name}" = excluded."${name}"`;
7671
7683
  } else if ("except" in merge) {
7672
- sql = mergeColumnsSql(columns, quotedColumns, target, merge.except);
7684
+ sql = mergeColumnsSql(columns, quotedColumns, target, [
7685
+ ...toArray(merge.except),
7686
+ ...runtimeDefaultColumns || emptyArray
7687
+ ]);
7673
7688
  } else {
7674
7689
  sql = `DO UPDATE SET ${merge.reduce((sql2, item, i) => {
7675
7690
  const name = shape[item]?.data.name || item;
@@ -7677,7 +7692,12 @@ const makeInsertSql = (ctx, q, query, quotedAs, isSubSql) => {
7677
7692
  }, "")}`;
7678
7693
  }
7679
7694
  } else {
7680
- sql = mergeColumnsSql(columns, quotedColumns, target);
7695
+ sql = mergeColumnsSql(
7696
+ columns,
7697
+ quotedColumns,
7698
+ target,
7699
+ runtimeDefaultColumns
7700
+ );
7681
7701
  }
7682
7702
  ctx.sql.push(sql);
7683
7703
  } else if (query.onConflict.set) {