pqb 0.18.33 → 0.19.0
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 +111 -27
- package/dist/index.js +29 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1072,7 +1072,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs, not) => {
|
|
|
1072
1072
|
const res = data(qb);
|
|
1073
1073
|
const expr = res instanceof Expression ? res : res.q.expr;
|
|
1074
1074
|
if (!(res instanceof Expression) && res.q.expr) {
|
|
1075
|
-
const q = "relationConfig" in res ? res.relationConfig.joinQuery(
|
|
1075
|
+
const q = "relationConfig" in res ? res.relationConfig.joinQuery(res, table) : res.clone();
|
|
1076
1076
|
q.q.select = [expr];
|
|
1077
1077
|
ands.push(`${prefix}(${makeSQL(q, ctx).text})`);
|
|
1078
1078
|
} else {
|
|
@@ -1306,7 +1306,7 @@ const processJoinItem = (ctx, table, query, item, quotedAs) => {
|
|
|
1306
1306
|
if (typeof first === "string") {
|
|
1307
1307
|
if (first in table.relations) {
|
|
1308
1308
|
const { query: toQuery, joinQuery } = table.relations[first].relationConfig;
|
|
1309
|
-
const jq = joinQuery(
|
|
1309
|
+
const jq = joinQuery(toQuery, table);
|
|
1310
1310
|
const { q: j } = jq;
|
|
1311
1311
|
const tableName = typeof j.from === "string" ? j.from : jq.table;
|
|
1312
1312
|
target = quoteSchemaAndTable(j.schema, tableName);
|
|
@@ -1434,8 +1434,8 @@ const processArgs = (args, ctx, table, query, first, joinAs, joinShape, quotedAs
|
|
|
1434
1434
|
base = base.as(q.q.as);
|
|
1435
1435
|
}
|
|
1436
1436
|
const { q: query2 } = first.joinQueryAfterCallback(
|
|
1437
|
-
|
|
1438
|
-
|
|
1437
|
+
base,
|
|
1438
|
+
table
|
|
1439
1439
|
);
|
|
1440
1440
|
if (query2.and) {
|
|
1441
1441
|
pushQueryArray(q, "and", query2.and);
|
|
@@ -2429,16 +2429,18 @@ const makeRegexToFindInSql = (value) => {
|
|
|
2429
2429
|
return new RegExp(`${value}(?=(?:[^']*'[^']*')*[^']*$)`, "g");
|
|
2430
2430
|
};
|
|
2431
2431
|
const resolveSubQueryCallback = (q, cb) => {
|
|
2432
|
-
const { isSubQuery } = q.q;
|
|
2432
|
+
const { isSubQuery, relChain } = q.q;
|
|
2433
2433
|
q.q.isSubQuery = true;
|
|
2434
|
+
q.q.relChain = void 0;
|
|
2434
2435
|
const result = cb(q);
|
|
2435
2436
|
q.q.isSubQuery = isSubQuery;
|
|
2437
|
+
q.q.relChain = relChain;
|
|
2436
2438
|
return result;
|
|
2437
2439
|
};
|
|
2438
2440
|
const joinSubQuery = (q, sub) => {
|
|
2439
2441
|
if (!("relationConfig" in sub))
|
|
2440
2442
|
return sub;
|
|
2441
|
-
return sub.relationConfig.joinQuery(
|
|
2443
|
+
return sub.relationConfig.joinQuery(sub, q);
|
|
2442
2444
|
};
|
|
2443
2445
|
|
|
2444
2446
|
const pushQueryArray = (q, key, value) => {
|
|
@@ -5814,8 +5816,8 @@ const _joinLateral = (q, type, arg, cb, as) => {
|
|
|
5814
5816
|
let result = cb(query);
|
|
5815
5817
|
if (relation) {
|
|
5816
5818
|
result = relation.relationConfig.joinQuery(
|
|
5817
|
-
|
|
5818
|
-
|
|
5819
|
+
result,
|
|
5820
|
+
q
|
|
5819
5821
|
);
|
|
5820
5822
|
}
|
|
5821
5823
|
const joinKey = as || result.q.as || result.table;
|
|
@@ -5886,7 +5888,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
5886
5888
|
if (typeof value === "function") {
|
|
5887
5889
|
value = resolveSubQueryCallback(q, value);
|
|
5888
5890
|
if (!isExpression(value) && value.joinQuery) {
|
|
5889
|
-
value = value.joinQuery(
|
|
5891
|
+
value = value.joinQuery(value, q);
|
|
5890
5892
|
let query;
|
|
5891
5893
|
const returnType = value.q.returnType;
|
|
5892
5894
|
if (!returnType || returnType === "all") {
|
|
@@ -6183,7 +6185,7 @@ class QueryGet {
|
|
|
6183
6185
|
* It will throw `NotFoundError` when not found.
|
|
6184
6186
|
*
|
|
6185
6187
|
* ```ts
|
|
6186
|
-
* import { NumberColumn } from '
|
|
6188
|
+
* import { NumberColumn } from 'orchid-orm';
|
|
6187
6189
|
*
|
|
6188
6190
|
* const firstName: string = await db.table.get('name');
|
|
6189
6191
|
*
|
|
@@ -7467,7 +7469,7 @@ class JsonModifiers extends QueryBase {
|
|
|
7467
7469
|
* Selects a value from JSON data using a JSON path.
|
|
7468
7470
|
*
|
|
7469
7471
|
* ```ts
|
|
7470
|
-
* import { columnTypes } from '
|
|
7472
|
+
* import { columnTypes } from 'orchid-orm';
|
|
7471
7473
|
*
|
|
7472
7474
|
* db.table.jsonPathQuery(
|
|
7473
7475
|
* columnTypes.text(3, 100), // type of the value
|
|
@@ -8054,7 +8056,7 @@ class With {
|
|
|
8054
8056
|
* Add Common Table Expression (CTE) to the query.
|
|
8055
8057
|
*
|
|
8056
8058
|
* ```ts
|
|
8057
|
-
* import { columnTypes } from '
|
|
8059
|
+
* import { columnTypes } from 'orchid-orm';
|
|
8058
8060
|
* import { NumberColumn } from './number';
|
|
8059
8061
|
*
|
|
8060
8062
|
* // .with optionally accepts such options:
|
|
@@ -8559,7 +8561,7 @@ class Update {
|
|
|
8559
8561
|
* To make sure that at least one row was updated use `updateOrThrow`:
|
|
8560
8562
|
*
|
|
8561
8563
|
* ```ts
|
|
8562
|
-
* import { NotFoundError } from '
|
|
8564
|
+
* import { NotFoundError } from 'orchid-orm';
|
|
8563
8565
|
*
|
|
8564
8566
|
* try {
|
|
8565
8567
|
* // updatedCount is guaranteed to be greater than 0
|
|
@@ -9895,6 +9897,20 @@ class QueryMethods {
|
|
|
9895
9897
|
* await selectFollowing(db.user.select('id', 'name'), currentUser);
|
|
9896
9898
|
* ```
|
|
9897
9899
|
*
|
|
9900
|
+
* To get the result type of query helper, use `QueryHelperResult` type:
|
|
9901
|
+
*
|
|
9902
|
+
* ```ts
|
|
9903
|
+
* import { QueryHelperResult } from 'orchid-orm';
|
|
9904
|
+
*
|
|
9905
|
+
* const selectHelper = db.table.makeHelper((q) => q.select('id', 'name'));
|
|
9906
|
+
*
|
|
9907
|
+
* // This type is identical to `db.table.select('id', 'name')`
|
|
9908
|
+
* type SelectQuery = QueryHelperResult<typeof selectHelper>;
|
|
9909
|
+
*
|
|
9910
|
+
* // Await to get result, the type is `{ id: number, name: string }[]`
|
|
9911
|
+
* type Result = Awaited<QueryHelperResult<typeof selectHelper>>;
|
|
9912
|
+
* ```
|
|
9913
|
+
*
|
|
9898
9914
|
* @param fn - helper function
|
|
9899
9915
|
*/
|
|
9900
9916
|
makeHelper(fn) {
|