pqb 0.36.13 → 0.36.15
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 +29 -19
- package/dist/index.js +27 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1906,18 +1906,6 @@ const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) =
|
|
|
1906
1906
|
}
|
|
1907
1907
|
return `"${tableName}"."${key}"`;
|
|
1908
1908
|
};
|
|
1909
|
-
const columnToSqlWithAs = (ctx, data, column, quotedAs, select) => {
|
|
1910
|
-
const index = column.indexOf(".");
|
|
1911
|
-
return index !== -1 ? tableColumnToSqlWithAs(
|
|
1912
|
-
ctx,
|
|
1913
|
-
data,
|
|
1914
|
-
column,
|
|
1915
|
-
column.slice(0, index),
|
|
1916
|
-
column.slice(index + 1),
|
|
1917
|
-
quotedAs,
|
|
1918
|
-
select
|
|
1919
|
-
) : ownColumnToSqlWithAs(ctx, data, column, quotedAs, select);
|
|
1920
|
-
};
|
|
1921
1909
|
const tableColumnToSqlWithAs = (ctx, data, column, table, key, quotedAs, select) => {
|
|
1922
1910
|
var _a, _b, _c;
|
|
1923
1911
|
if (key === "*") {
|
|
@@ -4541,11 +4529,9 @@ class SelectItemExpression extends Expression {
|
|
|
4541
4529
|
if (value)
|
|
4542
4530
|
Object.assign(this, value.operators);
|
|
4543
4531
|
}
|
|
4544
|
-
// `makeSQL` acts similarly to how select args are handled
|
|
4545
|
-
// except that it will use non-aliasing `columnToSql` when `ctx.aliasValue` is true,
|
|
4546
|
-
// it is needed for relation sub-queries that returns a single column.
|
|
4532
|
+
// `makeSQL` acts similarly to how select args are handled
|
|
4547
4533
|
makeSQL(ctx, quotedAs) {
|
|
4548
|
-
return typeof this.item === "string" ? this.item === "*" ? selectAllSql(this.query, this.q, quotedAs) :
|
|
4534
|
+
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);
|
|
4549
4535
|
}
|
|
4550
4536
|
}
|
|
4551
4537
|
|
|
@@ -7887,8 +7873,6 @@ const _queryDelete = (query) => {
|
|
|
7887
7873
|
};
|
|
7888
7874
|
class Delete {
|
|
7889
7875
|
/**
|
|
7890
|
-
* It is aliased to `del` because `delete` is a reserved word in JavaScript.
|
|
7891
|
-
*
|
|
7892
7876
|
* This method deletes one or more rows, based on other conditions specified in the query.
|
|
7893
7877
|
*
|
|
7894
7878
|
* By default, `delete` will return a count of deleted records.
|
|
@@ -9831,22 +9815,16 @@ class Where {
|
|
|
9831
9815
|
*
|
|
9832
9816
|
* ### JSONB column operators
|
|
9833
9817
|
*
|
|
9834
|
-
*
|
|
9818
|
+
* JSON functions are available only for the `jsonb` column, note that the `json` type has text operators instead.
|
|
9835
9819
|
*
|
|
9836
|
-
*
|
|
9820
|
+
* You can use [jsonPathQueryFirst](/guide/json.html#jsonpathqueryfirst) to filter by a JSON value, follow the link for details.
|
|
9837
9821
|
*
|
|
9838
|
-
*
|
|
9822
|
+
* The value can be of any type, it can also be returned from a sub-query, raw SQL expression.
|
|
9839
9823
|
*
|
|
9840
9824
|
* ```ts
|
|
9841
|
-
* db.table.where(
|
|
9842
|
-
* jsonbColumn
|
|
9843
|
-
*
|
|
9844
|
-
* '$.name', // first element is JSON path
|
|
9845
|
-
* '=', // second argument is comparison operator
|
|
9846
|
-
* 'value', // third argument is a value to compare with
|
|
9847
|
-
* ],
|
|
9848
|
-
* },
|
|
9849
|
-
* });
|
|
9825
|
+
* db.table.where((q) =>
|
|
9826
|
+
* q.get('jsonbColumn').jsonPathQueryFirst('$.name').equals(value),
|
|
9827
|
+
* );
|
|
9850
9828
|
* ```
|
|
9851
9829
|
*
|
|
9852
9830
|
* `jsonSupersetOf`: check if the column value is a superset of provided value.
|
|
@@ -9872,7 +9850,7 @@ class Where {
|
|
|
9872
9850
|
* ```ts
|
|
9873
9851
|
* db.table.where({
|
|
9874
9852
|
* jsonbColumn: {
|
|
9875
|
-
*
|
|
9853
|
+
* jsonSubsetOf: { a: 1 },
|
|
9876
9854
|
* },
|
|
9877
9855
|
* });
|
|
9878
9856
|
* ```
|
|
@@ -11288,14 +11266,14 @@ function enableSoftDelete(q, table, shape, softDelete, scopes) {
|
|
|
11288
11266
|
};
|
|
11289
11267
|
scopes.deleted = scope;
|
|
11290
11268
|
((_b = (_a = q.q).scopes) != null ? _b : _a.scopes = {}).nonDeleted = scope;
|
|
11291
|
-
const _del = _softDelete(column);
|
|
11269
|
+
const _del = _softDelete(column, q.internal.nowSQL);
|
|
11292
11270
|
q.baseQuery.delete = function() {
|
|
11293
11271
|
return _del.call(this.clone());
|
|
11294
11272
|
};
|
|
11295
11273
|
}
|
|
11296
11274
|
const nowSql = new RawSQL("now()");
|
|
11297
|
-
const _softDelete = (column) => {
|
|
11298
|
-
const set = { [column]: nowSql };
|
|
11275
|
+
const _softDelete = (column, customNowSQL) => {
|
|
11276
|
+
const set = { [column]: customNowSQL ? new RawSQL(customNowSQL) : nowSql };
|
|
11299
11277
|
return function() {
|
|
11300
11278
|
return _queryUpdate(this, set);
|
|
11301
11279
|
};
|
|
@@ -12343,6 +12321,7 @@ class Db {
|
|
|
12343
12321
|
snakeCase: options.snakeCase,
|
|
12344
12322
|
noPrimaryKey: options.noPrimaryKey === "ignore",
|
|
12345
12323
|
comment: options.comment,
|
|
12324
|
+
nowSQL: options.nowSQL,
|
|
12346
12325
|
tableData
|
|
12347
12326
|
};
|
|
12348
12327
|
this.baseQuery = this;
|
|
@@ -12584,14 +12563,12 @@ const createDb = (_a) => {
|
|
|
12584
12563
|
log,
|
|
12585
12564
|
logger,
|
|
12586
12565
|
snakeCase,
|
|
12587
|
-
nowSQL,
|
|
12588
12566
|
schemaConfig = defaultSchemaConfig,
|
|
12589
12567
|
columnTypes: ctOrFn = makeColumnTypes(schemaConfig)
|
|
12590
12568
|
} = _b, options = __objRest(_b, [
|
|
12591
12569
|
"log",
|
|
12592
12570
|
"logger",
|
|
12593
12571
|
"snakeCase",
|
|
12594
|
-
"nowSQL",
|
|
12595
12572
|
"schemaConfig",
|
|
12596
12573
|
"columnTypes"
|
|
12597
12574
|
]);
|
|
@@ -12602,6 +12579,7 @@ const createDb = (_a) => {
|
|
|
12602
12579
|
logger,
|
|
12603
12580
|
autoPreparedStatements: (_a2 = options.autoPreparedStatements) != null ? _a2 : false,
|
|
12604
12581
|
noPrimaryKey: (_b2 = options.noPrimaryKey) != null ? _b2 : "error",
|
|
12582
|
+
nowSQL: options.nowSQL,
|
|
12605
12583
|
snakeCase
|
|
12606
12584
|
};
|
|
12607
12585
|
const ct = typeof ctOrFn === "function" ? ctOrFn(makeColumnTypes(schemaConfig)) : ctOrFn;
|
|
@@ -12616,16 +12594,19 @@ const createDb = (_a) => {
|
|
|
12616
12594
|
commonOptions,
|
|
12617
12595
|
options
|
|
12618
12596
|
);
|
|
12619
|
-
const
|
|
12620
|
-
|
|
12621
|
-
|
|
12622
|
-
|
|
12623
|
-
|
|
12624
|
-
|
|
12625
|
-
|
|
12626
|
-
|
|
12627
|
-
|
|
12628
|
-
|
|
12597
|
+
const { nowSQL } = options;
|
|
12598
|
+
const tableConstructor = (table, shape, dataFn, options2) => {
|
|
12599
|
+
return new Db(
|
|
12600
|
+
adapter,
|
|
12601
|
+
qb,
|
|
12602
|
+
table,
|
|
12603
|
+
typeof shape === "function" ? getColumnTypes(ct, shape, nowSQL, options2 == null ? void 0 : options2.language) : shape,
|
|
12604
|
+
ct,
|
|
12605
|
+
transactionStorage,
|
|
12606
|
+
__spreadValues(__spreadValues({}, commonOptions), options2),
|
|
12607
|
+
parseTableData(dataFn)
|
|
12608
|
+
);
|
|
12609
|
+
};
|
|
12629
12610
|
const db = Object.assign(tableConstructor, qb, {
|
|
12630
12611
|
adapter,
|
|
12631
12612
|
close: () => adapter.close()
|