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