pqb 0.40.8 → 0.40.9

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
@@ -803,8 +803,8 @@ const columnCode = (type, ctx, key, code, data = type.data, skip) => {
803
803
  addCode(code, part);
804
804
  }
805
805
  }
806
- if (data.isHidden)
807
- addCode(code, ".hidden()");
806
+ if (data.explicitSelect)
807
+ addCode(code, ".select(false)");
808
808
  if (data.isNullable)
809
809
  addCode(code, ".nullable()");
810
810
  if (type.encodeFn && type.encodeFn !== (skip == null ? void 0 : skip.encodeFn))
@@ -2356,7 +2356,7 @@ const getArgQueryTarget = (ctx, first, joinSubQuery, cloned) => {
2356
2356
  }
2357
2357
  };
2358
2358
  const subJoinToSql = (ctx, jq, innerAs, outerAs, cloned) => {
2359
- if (!jq.q.select && jq.internal.columnsForSelectAll) {
2359
+ if (!jq.q.select && jq.q.selectAllColumns) {
2360
2360
  if (!cloned)
2361
2361
  jq = jq.clone();
2362
2362
  jq.q.select = [new RawSQL(`${innerAs}.*`)];
@@ -2693,7 +2693,7 @@ const _join = (query, require2, type, first, args) => {
2693
2693
  );
2694
2694
  if (joinKey && "s" in joinArgs && joinArgs.s) {
2695
2695
  const j = "j" in joinArgs ? (_b = joinArgs.r) != null ? _b : joinArgs.j : "r" in joinArgs ? joinArgs.r : joinArgs.q;
2696
- if (j.q.select || !j.internal.columnsForSelectAll) {
2696
+ if (j.q.select || !j.q.selectAllColumns) {
2697
2697
  const shape2 = getShapeFromSelect(j, true);
2698
2698
  setQueryObjectValue(
2699
2699
  query,
@@ -4713,7 +4713,7 @@ class SelectItemExpression extends Expression {
4713
4713
  }
4714
4714
  // `makeSQL` acts similarly to how select args are handled
4715
4715
  makeSQL(ctx, quotedAs) {
4716
- return typeof this.item === "string" ? this.item === "*" ? selectAllSql(this.query, this.q, quotedAs) : columnToSql(ctx, this.q, this.q.shape, this.item, quotedAs, true) : this.item.toSQL(ctx, quotedAs);
4716
+ return typeof this.item === "string" ? this.item === "*" ? selectAllSql(this.q, quotedAs) : columnToSql(ctx, this.q, this.q.shape, this.item, quotedAs, true) : this.item.toSQL(ctx, quotedAs);
4717
4717
  }
4718
4718
  }
4719
4719
 
@@ -4847,12 +4847,14 @@ function queryFrom(self, arg) {
4847
4847
  data.batchParsers = q.q.batchParsers;
4848
4848
  }
4849
4849
  data.from = arg;
4850
+ data.selectAllColumns = data.selectAllKeys = void 0;
4850
4851
  return self;
4851
4852
  }
4852
4853
  function queryFromSql(self, args) {
4853
4854
  const data = self.q;
4854
4855
  data.as || (data.as = "t");
4855
4856
  data.from = sqlQueryArgsToExpression(args);
4857
+ data.selectAllColumns = data.selectAllKeys = void 0;
4856
4858
  return self;
4857
4859
  }
4858
4860
  class FromMethods {
@@ -4967,11 +4969,11 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
4967
4969
  if (item === "*") {
4968
4970
  if (hookSelect) {
4969
4971
  selected != null ? selected : selected = {};
4970
- for (const key in table.internal.columnsKeysForSelectAll || query.shape) {
4972
+ for (const key in query.selectAllKeys || query.shape) {
4971
4973
  selected[key] = quotedAs;
4972
4974
  }
4973
4975
  }
4974
- sql = selectAllSql(table, query, quotedAs);
4976
+ sql = selectAllSql(query, quotedAs);
4975
4977
  } else {
4976
4978
  const index = item.indexOf(".");
4977
4979
  if (index !== -1) {
@@ -5073,15 +5075,15 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
5073
5075
  list.push(sql);
5074
5076
  }
5075
5077
  }
5076
- return list.length ? list.join(", ") : query.select ? "" : selectAllSql(table, query, quotedAs);
5078
+ return list.length ? list.join(", ") : query.select ? "" : selectAllSql(query, quotedAs);
5077
5079
  };
5078
5080
  function selectedObjectToSQL(ctx, quotedAs, item) {
5079
5081
  const sql = item.toSQL(ctx, quotedAs);
5080
5082
  return ctx.aliasValue ? `${sql} r` : sql;
5081
5083
  }
5082
- const selectAllSql = (table, query, quotedAs) => {
5084
+ const selectAllSql = (query, quotedAs) => {
5083
5085
  var _a, _b, _c;
5084
- return ((_a = query.join) == null ? void 0 : _a.length) ? ((_b = table.internal.columnsForSelectAll) == null ? void 0 : _b.map((item) => `${quotedAs}.${item}`).join(", ")) || `${quotedAs}.*` : ((_c = table.internal.columnsForSelectAll) == null ? void 0 : _c.join(", ")) || "*";
5086
+ return ((_a = query.join) == null ? void 0 : _a.length) ? ((_b = query.selectAllColumns) == null ? void 0 : _b.map((item) => `${quotedAs}.${item}`).join(", ")) || `${quotedAs}.*` : ((_c = query.selectAllColumns) == null ? void 0 : _c.join(", ")) || "*";
5085
5087
  };
5086
5088
  const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
5087
5089
  var _a, _b, _c;
@@ -5275,7 +5277,7 @@ const pushWithSql = (ctx, items) => {
5275
5277
 
5276
5278
  const checkIfASimpleQuery = (q) => {
5277
5279
  var _a, _b;
5278
- if (q.q.returnType && q.q.returnType !== "all" || q.internal.columnsForSelectAll || ((_a = q.q.and) == null ? void 0 : _a.length) || ((_b = q.q.or) == null ? void 0 : _b.length) || q.q.scopes)
5280
+ if (q.q.returnType && q.q.returnType !== "all" || q.q.selectAllColumns || ((_a = q.q.and) == null ? void 0 : _a.length) || ((_b = q.q.or) == null ? void 0 : _b.length) || q.q.scopes)
5279
5281
  return false;
5280
5282
  const keys = Object.keys(q.q);
5281
5283
  return !keys.some((key) => queryKeysOfNotSimpleQuery.includes(key));
@@ -5303,7 +5305,7 @@ const pushFromAndAs = (ctx, table, data, quotedAs) => {
5303
5305
  const from = getFrom(ctx, table, data, quotedAs);
5304
5306
  sql += from;
5305
5307
  if (data.as && quotedAs && quotedAs !== from) {
5306
- sql += ` AS ${quotedAs}`;
5308
+ sql += ` ${quotedAs}`;
5307
5309
  }
5308
5310
  for (const as in data.sources) {
5309
5311
  const source = data.sources[as];
@@ -9437,16 +9439,17 @@ var __spreadValues$5 = (a, b) => {
9437
9439
  }
9438
9440
  return a;
9439
9441
  };
9440
- const mergableObjects = {
9441
- shape: true,
9442
- withShapes: true,
9443
- parsers: true,
9444
- defaults: true,
9445
- joinedShapes: true,
9446
- joinedParsers: true,
9447
- joinedBatchParsers: true,
9448
- selectedComputeds: true
9449
- };
9442
+ const mergableObjects = /* @__PURE__ */ new Set([
9443
+ "shape",
9444
+ "withShapes",
9445
+ "parsers",
9446
+ "defaults",
9447
+ "joinedShapes",
9448
+ "joinedParsers",
9449
+ "joinedBatchParsers",
9450
+ "selectedComputeds"
9451
+ ]);
9452
+ const dontMergeArrays = /* @__PURE__ */ new Set(["selectAllColumns", "selectAllKeys"]);
9450
9453
  class MergeQueryMethods {
9451
9454
  merge(q) {
9452
9455
  const query = this.clone();
@@ -9462,8 +9465,10 @@ class MergeQueryMethods {
9462
9465
  break;
9463
9466
  case "object":
9464
9467
  if (Array.isArray(value)) {
9465
- a[key] = a[key] ? [...a[key], ...value] : value;
9466
- } else if (mergableObjects[key]) {
9468
+ if (!dontMergeArrays.has(key)) {
9469
+ a[key] = a[key] ? [...a[key], ...value] : value;
9470
+ }
9471
+ } else if (mergableObjects.has(key)) {
9467
9472
  a[key] = a[key] ? __spreadValues$5(__spreadValues$5({}, a[key]), value) : value;
9468
9473
  } else if (key === "union") {
9469
9474
  a[key] = a[key] ? {
@@ -11383,7 +11388,11 @@ class QueryUpsertOrCreate {
11383
11388
  if (!isObjectEmpty(updateData)) {
11384
11389
  _queryUpdate(q, updateData);
11385
11390
  }
11386
- return orCreate(q, data.create, updateData, mergeData);
11391
+ const c = orCreate(q, data.create, updateData, mergeData);
11392
+ if (!c.q.select) {
11393
+ c.q.returnType = "void";
11394
+ }
11395
+ return c;
11387
11396
  }
11388
11397
  /**
11389
11398
  * `orCreate` creates a record only if it was not found by conditions.
@@ -12684,7 +12693,7 @@ class Db {
12684
12693
  const parsers = {};
12685
12694
  let hasParsers = false;
12686
12695
  let modifyQuery = void 0;
12687
- let hasCustomName = false;
12696
+ let prepareSelectAll = false;
12688
12697
  const { snakeCase } = options;
12689
12698
  for (const key in shape) {
12690
12699
  const column = shape[key];
@@ -12694,14 +12703,17 @@ class Db {
12694
12703
  parsers[key] = column.parseFn;
12695
12704
  }
12696
12705
  if (column.data.name) {
12697
- hasCustomName = true;
12706
+ prepareSelectAll = true;
12698
12707
  } else if (snakeCase) {
12699
12708
  const snakeName = toSnakeCase(key);
12700
12709
  if (snakeName !== key) {
12701
- hasCustomName = true;
12710
+ prepareSelectAll = true;
12702
12711
  column.data.name = snakeName;
12703
12712
  }
12704
12713
  }
12714
+ if (column.data.explicitSelect) {
12715
+ prepareSelectAll = true;
12716
+ }
12705
12717
  const { modifyQuery: mq } = column.data;
12706
12718
  if (mq) {
12707
12719
  modifyQuery = pushOrNewArray(modifyQuery, (q) => mq(q, column));
@@ -12721,17 +12733,6 @@ class Db {
12721
12733
  }
12722
12734
  }
12723
12735
  }
12724
- if (hasCustomName) {
12725
- const list = [];
12726
- for (const key in shape) {
12727
- const column = shape[key];
12728
- list.push(
12729
- column.data.name ? `"${column.data.name}" AS "${key}"` : `"${key}"`
12730
- );
12731
- }
12732
- this.internal.columnsForSelectAll = list;
12733
- this.internal.columnsKeysForSelectAll = __spreadValues({}, shape);
12734
- }
12735
12736
  this.q = {
12736
12737
  adapter,
12737
12738
  shape,
@@ -12764,21 +12765,22 @@ class Db {
12764
12765
  const columns = Object.keys(
12765
12766
  shape
12766
12767
  );
12767
- const { toSQL } = this;
12768
12768
  this.columns = columns;
12769
- this.defaultSelectColumns = columns.filter(
12770
- (column) => !shape[column].data.isHidden
12771
- );
12772
12769
  if (options.computed)
12773
12770
  applyComputedColumns(this, options.computed);
12774
- const defaultSelect = this.defaultSelectColumns.length === columns.length ? void 0 : this.defaultSelectColumns;
12775
- this.toSQL = defaultSelect ? function(options2) {
12776
- const q = this.clone();
12777
- if (!q.q.select) {
12778
- q.q.select = defaultSelect;
12779
- }
12780
- return toSQL.call(q, options2);
12781
- } : toSQL;
12771
+ if (prepareSelectAll) {
12772
+ const list = [];
12773
+ for (const key in shape) {
12774
+ const column = shape[key];
12775
+ if (!column.data.explicitSelect) {
12776
+ list.push(
12777
+ column.data.name ? `"${column.data.name}" AS "${key}"` : `"${key}"`
12778
+ );
12779
+ }
12780
+ }
12781
+ this.q.selectAllColumns = list;
12782
+ this.q.selectAllKeys = __spreadValues({}, shape);
12783
+ }
12782
12784
  if (modifyQuery) {
12783
12785
  for (const cb of modifyQuery) {
12784
12786
  cb(this);