pqb 0.30.1 → 0.30.2
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 +60 -23
- package/dist/index.js +36 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2019,7 +2019,7 @@ const processAnds = (and, ctx, table, query, quotedAs, parens) => {
|
|
|
2019
2019
|
return parens && ands.length > 1 ? `(${sql})` : sql;
|
|
2020
2020
|
};
|
|
2021
2021
|
const processWhere = (ands, ctx, table, query, data, quotedAs) => {
|
|
2022
|
-
var _a, _b;
|
|
2022
|
+
var _a, _b, _c, _d;
|
|
2023
2023
|
if (typeof data === "function") {
|
|
2024
2024
|
const qb = Object.create(table);
|
|
2025
2025
|
qb.q = getClonedQueryData(query);
|
|
@@ -2181,7 +2181,8 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
|
|
|
2181
2181
|
column = quotedAs === quoted ? query.shape[name] : (_b = (_a = query.joinedShapes) == null ? void 0 : _a[table2]) == null ? void 0 : _b[name];
|
|
2182
2182
|
quotedColumn = simpleColumnToSQL(ctx, name, column, quoted);
|
|
2183
2183
|
} else {
|
|
2184
|
-
|
|
2184
|
+
column = (_d = (_c = query.joinedShapes) == null ? void 0 : _c[key]) == null ? void 0 : _d.value;
|
|
2185
|
+
quotedColumn = `"${key}".r`;
|
|
2185
2186
|
}
|
|
2186
2187
|
if (!column || !quotedColumn) {
|
|
2187
2188
|
throw new Error(`Unknown column ${key} provided to condition`);
|
|
@@ -3454,6 +3455,8 @@ const getShapeFromSelect = (q, isSubQuery) => {
|
|
|
3454
3455
|
}
|
|
3455
3456
|
}
|
|
3456
3457
|
}
|
|
3458
|
+
} else if (isExpression(item)) {
|
|
3459
|
+
result.value = item.result.value;
|
|
3457
3460
|
}
|
|
3458
3461
|
}
|
|
3459
3462
|
}
|
|
@@ -7188,15 +7191,14 @@ class Join {
|
|
|
7188
7191
|
* profile: (q) => q.profile,
|
|
7189
7192
|
* });
|
|
7190
7193
|
*
|
|
7191
|
-
* // select posts with counts of comments, order by comments count
|
|
7194
|
+
* // select posts with counts of comments, filter and order by comments count
|
|
7192
7195
|
* // result type is Array<Post & { commentsCount: number }>
|
|
7193
7196
|
* await db.post
|
|
7194
7197
|
* .select('*', {
|
|
7195
7198
|
* commentsCount: (q) => q.comments.count(),
|
|
7196
7199
|
* })
|
|
7197
|
-
* .
|
|
7198
|
-
*
|
|
7199
|
-
* });
|
|
7200
|
+
* .where({ commentsCount: { gt: 10 } })
|
|
7201
|
+
* .order({ commentsCount: 'DESC' });
|
|
7200
7202
|
*
|
|
7201
7203
|
* // select authors with array of their book titles
|
|
7202
7204
|
* // result type is Array<Author & { books: string[] }>
|
|
@@ -11064,6 +11066,34 @@ class QueryMethods {
|
|
|
11064
11066
|
}
|
|
11065
11067
|
return new RefExpression(column, q.q, arg);
|
|
11066
11068
|
}
|
|
11069
|
+
/**
|
|
11070
|
+
* Narrows a part of the query output type.
|
|
11071
|
+
* Use with caution, type-safety isn't guaranteed with it.
|
|
11072
|
+
* This is similar so using `as` keyword from TypeScript, except that it applies only to a part of the result.
|
|
11073
|
+
*
|
|
11074
|
+
* The syntax `()<{ ... }>()` is enforced by internal limitations.
|
|
11075
|
+
*
|
|
11076
|
+
* ```ts
|
|
11077
|
+
* const rows = db.table
|
|
11078
|
+
* // filter out records where the `nullableColumn` is null
|
|
11079
|
+
* .where({ nullableColumn: { not: null } });
|
|
11080
|
+
* // narrows only a specified column, the rest of result is unchanged
|
|
11081
|
+
* .narrowType()<{ nullableColumn: string }>()
|
|
11082
|
+
*
|
|
11083
|
+
* // the column had type `string | null`, now it is `string`
|
|
11084
|
+
* rows[0].nullableColumn
|
|
11085
|
+
*
|
|
11086
|
+
* // imagine that table has a enum column kind with variants 'first' | 'second'
|
|
11087
|
+
* // and a boolean `approved`
|
|
11088
|
+
* db.table
|
|
11089
|
+
* .where({ kind: 'first', approved: true })
|
|
11090
|
+
* // after applying such `where`, it's safe to narrow the type to receive the literal values
|
|
11091
|
+
* .narrowType()<{ kind: 'first', approved: true }>();
|
|
11092
|
+
* ```
|
|
11093
|
+
*/
|
|
11094
|
+
narrowType() {
|
|
11095
|
+
return () => this;
|
|
11096
|
+
}
|
|
11067
11097
|
}
|
|
11068
11098
|
applyMixins(QueryMethods, [
|
|
11069
11099
|
QueryBase,
|