pqb 0.3.3 → 0.3.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.js CHANGED
@@ -3008,14 +3008,6 @@ class ArrayOfColumnsObjects extends ColumnType {
3008
3008
  }
3009
3009
  class PluckResultColumnType extends ColumnType {
3010
3010
  }
3011
- class TableSchema {
3012
- constructor(shape) {
3013
- this.shape = shape;
3014
- this.primaryKeys = Object.entries(this.shape).filter(([, column]) => {
3015
- return column.isPrimaryKey;
3016
- }).map(([key]) => key);
3017
- }
3018
- }
3019
3011
 
3020
3012
  var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
3021
3013
  var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
@@ -5044,7 +5036,7 @@ class Update {
5044
5036
  return q._update(...args);
5045
5037
  }
5046
5038
  _update(...args) {
5047
- var _a, _b;
5039
+ var _a, _b, _c;
5048
5040
  const { query } = this;
5049
5041
  const data = args[0];
5050
5042
  const set = __spreadValues$1({}, data);
@@ -5086,12 +5078,14 @@ class Update {
5086
5078
  if ((state == null ? void 0 : state.updateLater) || appendRelationKeys.length && originalReturnType !== "all") {
5087
5079
  query.returnType = "all";
5088
5080
  if (state == null ? void 0 : state.updateLater) {
5089
- this.schema.primaryKeys.forEach((key) => {
5090
- var _a2, _b2;
5091
- if (!((_a2 = query.select) == null ? void 0 : _a2.includes("*")) && !((_b2 = query.select) == null ? void 0 : _b2.includes(key))) {
5092
- this._select(key);
5093
- }
5094
- });
5081
+ if (!((_c = query.select) == null ? void 0 : _c.includes("*"))) {
5082
+ this.primaryKeys.forEach((key) => {
5083
+ var _a2;
5084
+ if (!((_a2 = query.select) == null ? void 0 : _a2.includes(key))) {
5085
+ this._select(key);
5086
+ }
5087
+ });
5088
+ }
5095
5089
  }
5096
5090
  const { handleResult } = query;
5097
5091
  query.handleResult = async (q, queryResult) => {
@@ -5099,7 +5093,7 @@ class Update {
5099
5093
  if (state == null ? void 0 : state.updateLater) {
5100
5094
  await Promise.all(state.updateLaterPromises);
5101
5095
  const t = this.__model.clone().transacting(q);
5102
- const keys = this.schema.primaryKeys;
5096
+ const keys = this.primaryKeys;
5103
5097
  t._whereIn(
5104
5098
  keys,
5105
5099
  resultOfTypeAll.map((item) => keys.map((key) => item[key]))
@@ -5350,22 +5344,20 @@ class QueryMethods {
5350
5344
  _distinct(...columns) {
5351
5345
  return pushQueryArray(this, "distinct", columns);
5352
5346
  }
5353
- find(...args) {
5354
- return this.clone()._find(...args);
5347
+ find(value) {
5348
+ return this.clone()._find(value);
5355
5349
  }
5356
- _find(...args) {
5357
- const conditions = {};
5358
- this.schema.primaryKeys.forEach((key, i) => {
5359
- conditions[key] = args[i];
5360
- });
5361
- return this._where(conditions)._take();
5350
+ _find(value) {
5351
+ return this._where({
5352
+ [this.singlePrimaryKey]: value
5353
+ })._take();
5362
5354
  }
5363
- findOptional(...args) {
5364
- return this.clone()._findOptional(...args);
5355
+ findOptional(value) {
5356
+ return this.clone()._findOptional(value);
5365
5357
  }
5366
- _findOptional(...args) {
5358
+ _findOptional(value) {
5367
5359
  return this._find(
5368
- ...args
5360
+ value
5369
5361
  ).takeOptional();
5370
5362
  }
5371
5363
  findBy(...args) {
@@ -5532,7 +5524,12 @@ class Db {
5532
5524
  if (options == null ? void 0 : options.schema) {
5533
5525
  this.query.schema = options.schema;
5534
5526
  }
5535
- this.schema = new TableSchema(shape);
5527
+ this.primaryKeys = Object.keys(shape).filter(
5528
+ (key) => shape[key].isPrimaryKey
5529
+ );
5530
+ if (this.primaryKeys.length === 1) {
5531
+ this.singlePrimaryKey = this.primaryKeys[0];
5532
+ }
5536
5533
  const columns = Object.keys(
5537
5534
  shape
5538
5535
  );
@@ -5682,7 +5679,6 @@ exports.Select = Select;
5682
5679
  exports.SerialColumn = SerialColumn;
5683
5680
  exports.SmallIntColumn = SmallIntColumn;
5684
5681
  exports.SmallSerialColumn = SmallSerialColumn;
5685
- exports.TableSchema = TableSchema;
5686
5682
  exports.TextBaseColumn = TextBaseColumn;
5687
5683
  exports.TextColumn = TextColumn;
5688
5684
  exports.Then = Then;