pqb 0.18.18 → 0.18.20

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
@@ -3551,22 +3551,22 @@ const getColumnTypes = (types, fn, nowSQL, language, data = newTableData()) => {
3551
3551
  resetTableData(data);
3552
3552
  return fn(types);
3553
3553
  };
3554
- function sql(...args) {
3555
- const arg = args[0];
3556
- if (Array.isArray(arg)) {
3557
- return new RawSQL(args);
3558
- }
3559
- if (typeof args[0] === "string") {
3560
- return new RawSQL(args[0]);
3561
- }
3562
- if (args[1] !== void 0) {
3563
- return new RawSQL(args[1], arg);
3564
- }
3565
- return (...args2) => new RawSQL(args2, arg);
3566
- }
3567
3554
  const columnTypes = __spreadValues$9({
3568
3555
  name: orchidCore.name,
3569
- sql,
3556
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3557
+ sql(...args) {
3558
+ const arg = args[0];
3559
+ if (Array.isArray(arg)) {
3560
+ return new RawSQL(args);
3561
+ }
3562
+ if (typeof args[0] === "string") {
3563
+ return new RawSQL(args[0]);
3564
+ }
3565
+ if (args[1] !== void 0) {
3566
+ return new RawSQL(args[1], arg);
3567
+ }
3568
+ return (...args2) => new RawSQL(args2, arg);
3569
+ },
3570
3570
  smallint() {
3571
3571
  return new SmallIntColumn();
3572
3572
  },
@@ -3612,7 +3612,6 @@ const columnTypes = __spreadValues$9({
3612
3612
  text(min, max) {
3613
3613
  return new TextColumn(min, max);
3614
3614
  },
3615
- // `varchar` column with optional limit defaulting to 255.
3616
3615
  string(limit = 255) {
3617
3616
  return new VarCharColumn(limit);
3618
3617
  },
@@ -3733,12 +3732,7 @@ const columnTypes = __spreadValues$9({
3733
3732
  searchIndex(columns, options) {
3734
3733
  return this.index(columns, __spreadProps$5(__spreadValues$9({}, options), { tsVector: true }));
3735
3734
  },
3736
- constraint({
3737
- name: name2,
3738
- references,
3739
- check,
3740
- dropMode
3741
- }) {
3735
+ constraint({ name: name2, references, check, dropMode }) {
3742
3736
  var _a;
3743
3737
  ((_a = tableData.constraints) != null ? _a : tableData.constraints = []).push({
3744
3738
  name: name2,
@@ -8289,6 +8283,12 @@ var __spreadValues$3 = (a, b) => {
8289
8283
  };
8290
8284
  const applyCountChange = (self, op, data) => {
8291
8285
  self.q.type = "update";
8286
+ if (!self.q.select) {
8287
+ if (self.q.returnType === "oneOrThrow" || self.q.returnType === "valueOrThrow") {
8288
+ self.q.throwOnNotFound = true;
8289
+ }
8290
+ self.q.returnType = "rowCount";
8291
+ }
8292
8292
  let map;
8293
8293
  if (typeof data === "object") {
8294
8294
  map = {};
@@ -8606,17 +8606,33 @@ class Update {
8606
8606
  return this._update(arg);
8607
8607
  }
8608
8608
  /**
8609
- * Increments a column value by the specified amount. Optionally takes `returning` argument.
8609
+ * Increments a column by `1`, returns a count of updated records by default.
8610
8610
  *
8611
8611
  * ```ts
8612
- * // increment numericColumn column by 1, return updated records
8613
- * const result = await db.table
8614
- * .selectAll()
8612
+ * const updatedCount = await db.table
8613
+ * .where(...conditions)
8614
+ * .increment('numericColumn');
8615
+ * ```
8616
+ *
8617
+ * When using `find` or `get` it will throw `NotFoundError` when no records found.
8618
+ *
8619
+ * ```ts
8620
+ * // throws when not found
8621
+ * const updatedCount = await db.table.find(1).increment('numericColumn');
8622
+ *
8623
+ * // also throws when not found
8624
+ * const updatedCount2 = await db.table
8615
8625
  * .where(...conditions)
8626
+ * .get('columnName')
8616
8627
  * .increment('numericColumn');
8628
+ * ```
8629
+ *
8630
+ * Provide an object to increment multiple columns with different values.
8631
+ * Use `select` to specify columns to return.
8617
8632
  *
8633
+ * ```ts
8618
8634
  * // increment someColumn by 5 and otherColumn by 10, return updated records
8619
- * const result2 = await db.table
8635
+ * const result = await db.table
8620
8636
  * .selectAll()
8621
8637
  * .where(...conditions)
8622
8638
  * .increment({
@@ -8634,17 +8650,33 @@ class Update {
8634
8650
  return applyCountChange(this, "+", data);
8635
8651
  }
8636
8652
  /**
8637
- * Decrements a column value by the specified amount. Optionally takes `returning` argument.
8653
+ * Decrements a column by `1`, returns a count of updated records by default.
8638
8654
  *
8639
8655
  * ```ts
8640
- * // decrement numericColumn column by 1, return updated records
8641
- * const result = await db.table
8642
- * .selectAll()
8656
+ * const updatedCount = await db.table
8643
8657
  * .where(...conditions)
8644
8658
  * .decrement('numericColumn');
8659
+ * ```
8645
8660
  *
8661
+ * When using `find` or `get` it will throw `NotFoundError` when no records found.
8662
+ *
8663
+ * ```ts
8664
+ * // throws when not found
8665
+ * const updatedCount = await db.table.find(1).decrement('numericColumn');
8666
+ *
8667
+ * // also throws when not found
8668
+ * const updatedCount2 = await db.table
8669
+ * .where(...conditions)
8670
+ * .get('columnName')
8671
+ * .decrement('numericColumn');
8672
+ * ```
8673
+ *
8674
+ * Provide an object to decrement multiple columns with different values.
8675
+ * Use `select` to specify columns to return.
8676
+ *
8677
+ * ```ts
8646
8678
  * // decrement someColumn by 5 and otherColumn by 10, return updated records
8647
- * const result2 = await db.table
8679
+ * const result = await db.table
8648
8680
  * .selectAll()
8649
8681
  * .where(...conditions)
8650
8682
  * .decrement({
@@ -10193,7 +10225,9 @@ const createDb = (_a) => {
10193
10225
  noPrimaryKey: (_b2 = options.noPrimaryKey) != null ? _b2 : "error",
10194
10226
  snakeCase
10195
10227
  };
10196
- const ct = typeof ctOrFn === "function" ? ctOrFn(columnTypes) : ctOrFn;
10228
+ const ct = typeof ctOrFn === "function" ? ctOrFn(
10229
+ columnTypes
10230
+ ) : ctOrFn;
10197
10231
  if (snakeCase) {
10198
10232
  ct[orchidCore.snakeCaseKey] = true;
10199
10233
  }