pqb 0.5.0 → 0.5.2

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
@@ -684,7 +684,7 @@ const pushIn = (ands, prefix, quotedAs, values, arg) => {
684
684
  } else if (isRaw(arg.values)) {
685
685
  value = getRaw(arg.values, values);
686
686
  } else {
687
- const sql = arg.values.toSql({ values });
687
+ const sql = makeSql(arg.values, { values });
688
688
  value = `(${sql.text})`;
689
689
  }
690
690
  const columnsSql = arg.columns.map((column) => quoteFullColumn(column, quotedAs)).join(", ");
@@ -939,7 +939,7 @@ const pushSubQuerySql = (query, as, values, list) => {
939
939
  default:
940
940
  throw new UnhandledTypeError(returnType);
941
941
  }
942
- let subQuerySql = `(${query.toSql({ values }).text})`;
942
+ let subQuerySql = `(${makeSql(query, { values }).text})`;
943
943
  const { coalesceValue } = query.query;
944
944
  if (coalesceValue !== void 0) {
945
945
  const value = typeof coalesceValue === "object" && coalesceValue && isRaw(coalesceValue) ? getRaw(coalesceValue, values) : quote(coalesceValue);
@@ -1055,7 +1055,7 @@ const pushWithSql = (ctx, withData) => {
1055
1055
  if (isRaw(query)) {
1056
1056
  inner = getRaw(query, ctx.values);
1057
1057
  } else {
1058
- inner = query.toSql({ values: ctx.values }).text;
1058
+ inner = makeSql(query, { values: ctx.values }).text;
1059
1059
  }
1060
1060
  return `${options.recursive ? "RECURSIVE " : ""}${q(name)}${options.columns ? `(${options.columns.map(q).join(", ")})` : ""} AS ${options.materialized ? "MATERIALIZED " : options.notMaterialized ? "NOT MATERIALIZED " : ""}(${inner})`;
1061
1061
  }).join(", ")
@@ -1106,12 +1106,12 @@ const getFrom = (model, query, values) => {
1106
1106
  return getRaw(query.from, values);
1107
1107
  }
1108
1108
  if (!query.from.table) {
1109
- const sql = query.from.toSql({ values });
1109
+ const sql = makeSql(query.from, { values });
1110
1110
  return `(${sql.text})`;
1111
1111
  }
1112
1112
  const q = query.from.query;
1113
1113
  if (!checkIfASimpleQuery(q)) {
1114
- const sql = query.from.toSql({ values });
1114
+ const sql = makeSql(query.from, { values });
1115
1115
  return `(${sql.text})`;
1116
1116
  }
1117
1117
  return quoteSchemaAndTable(q.schema, query.from.table);
@@ -1158,7 +1158,7 @@ const pushInsertSql = (ctx, model, query, quotedAs) => {
1158
1158
  "select",
1159
1159
  isRaw(query.values) ? query.values : raw(encodeRow(ctx, query.values[0]))
1160
1160
  );
1161
- ctx.sql.push(q2.toSql({ values: ctx.values }).text);
1161
+ ctx.sql.push(makeSql(q2, { values: ctx.values }).text);
1162
1162
  } else {
1163
1163
  ctx.sql.push(
1164
1164
  `VALUES ${isRaw(query.values) ? getRaw(query.values, ctx.values) : query.values.map((row) => `(${encodeRow(ctx, row)})`).join(", ")}`
@@ -1400,7 +1400,7 @@ const makeSql = (model, { values = [] } = {}) => {
1400
1400
  if (isRaw(item.arg)) {
1401
1401
  itemSql = getRaw(item.arg, values);
1402
1402
  } else {
1403
- const argSql = item.arg.toSql({ values });
1403
+ const argSql = makeSql(item.arg, { values });
1404
1404
  itemSql = argSql.text;
1405
1405
  }
1406
1406
  sql.push(`${item.kind} ${item.wrap ? `(${itemSql})` : itemSql}`);
@@ -4206,13 +4206,13 @@ const processCreateItem = (item, rowIndex, ctx, columns, encoders, columnsMap, s
4206
4206
  item[key]
4207
4207
  ]);
4208
4208
  } else {
4209
+ const value = item[key];
4210
+ if ((!value.create || Array.isArray(value.create) && value.create.length === 0) && (!value.connect || Array.isArray(value.connect) && value.connect.length === 0) && (!value.connectOrCreate || Array.isArray(value.connectOrCreate) && value.connectOrCreate.length === 0))
4211
+ return;
4209
4212
  ctx.requiredReturning[ctx.relations[key].primaryKey] = true;
4210
4213
  if (!ctx.appendRelations[key])
4211
4214
  ctx.appendRelations[key] = [];
4212
- ctx.appendRelations[key].push([
4213
- rowIndex,
4214
- item[key]
4215
- ]);
4215
+ ctx.appendRelations[key].push([rowIndex, value]);
4216
4216
  }
4217
4217
  } else if (columnsMap[key] === void 0 && (shape[key] || shape === anyShape)) {
4218
4218
  columnsMap[key] = columns.length;
@@ -4774,7 +4774,7 @@ class Json {
4774
4774
  _json() {
4775
4775
  const q = this._wrap(this.__model.clone());
4776
4776
  q._getOptional(
4777
- this.raw(
4777
+ raw(
4778
4778
  queryTypeWithLimitOne[this.query.returnType] ? `row_to_json("t".*)` : `COALESCE(json_agg(row_to_json("t".*)), '[]')`
4779
4779
  )
4780
4780
  );
@@ -5155,6 +5155,9 @@ class Update {
5155
5155
  if (relations[key].type === "belongsTo") {
5156
5156
  prependRelations[key] = data[key];
5157
5157
  } else {
5158
+ const value = data[key];
5159
+ if (!value.set && !("upsert" in value) && (!value.disconnect || Array.isArray(value.disconnect) && value.disconnect.length === 0) && (!value.delete || Array.isArray(value.delete) && value.delete.length === 0) && (!value.update || Array.isArray(value.update.where) && value.update.where.length === 0) && (!value.create || Array.isArray(value.create) && value.create.length === 0))
5160
+ continue;
5158
5161
  if (!((_a = query.select) == null ? void 0 : _a.includes("*"))) {
5159
5162
  const primaryKey = relations[key].primaryKey;
5160
5163
  if (!((_b = query.select) == null ? void 0 : _b.includes(primaryKey))) {
@@ -5528,11 +5531,8 @@ class QueryMethods {
5528
5531
  wrap(query, as) {
5529
5532
  return this.clone()._wrap(query, as);
5530
5533
  }
5531
- _wrap(query, as) {
5532
- const sql = this.toSql();
5533
- return query.as(as != null ? as : "t")._from(
5534
- this.raw(`(${sql.text})`, ...sql.values)
5535
- );
5534
+ _wrap(query, as = "t") {
5535
+ return query.as(as)._from(this, as);
5536
5536
  }
5537
5537
  order(...args) {
5538
5538
  return this.clone()._order(...args);
@@ -5878,6 +5878,7 @@ exports.literal = literal;
5878
5878
  exports.logColors = logColors;
5879
5879
  exports.logParamToLogObject = logParamToLogObject;
5880
5880
  exports.makeRegexToFindInSql = makeRegexToFindInSql;
5881
+ exports.makeSql = makeSql;
5881
5882
  exports.map = map;
5882
5883
  exports.nativeEnum = nativeEnum;
5883
5884
  exports.newTableData = newTableData;