typeorm-extensions 2.2.0-rc.2 → 2.2.0-rc.3
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.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export type TypedGroupByOptions = {
|
|
2
2
|
/**
|
|
3
3
|
* Group by the quoted database column (`"ticket"."ticket_status"`) instead of `ticket.status`,
|
|
4
|
-
* which TypeORM maps to the column itself.
|
|
5
|
-
*
|
|
4
|
+
* which TypeORM maps to the column itself. Keys of an alias without metadata (a subquery in FROM)
|
|
5
|
+
* are quoted unless this is `false`: PostgreSQL folds an unquoted `sub.firstName` to `firstname`.
|
|
6
6
|
*/
|
|
7
7
|
useQuotes?: boolean;
|
|
8
8
|
};
|
|
@@ -47,10 +47,13 @@ export declare function isTypedJsonPath<Type extends ObjectLiteral>(builder: Whe
|
|
|
47
47
|
*/
|
|
48
48
|
export declare function getTypedSingleColumnKey<Type extends ObjectLiteral>(builder: WhereExpressionBuilder, callback: KeyProxyCallback<Type>, methodName: string, jsonOptions?: JsonPathSqlOptions): string;
|
|
49
49
|
/**
|
|
50
|
-
* Key for typed select / order / distinct on a SelectQueryBuilder.
|
|
50
|
+
* Key for typed select / order / distinct / group by on a SelectQueryBuilder.
|
|
51
51
|
*
|
|
52
52
|
* Without quotes it is `alias.propertyPath` (`user.name`, `images.url`, `p.address.city`),
|
|
53
53
|
* which TypeORM maps to the column itself. With `useQuotes` it is the quoted database column
|
|
54
|
-
* (`"t"."ticket_status"`), since TypeORM doesn't map quoted keys.
|
|
54
|
+
* (`"t"."ticket_status"`), since TypeORM doesn't map quoted keys. An alias of the query without
|
|
55
|
+
* metadata (a subquery or a CTE in FROM or a join) is quoted unless `useQuotes` is `false`:
|
|
56
|
+
* TypeORM leaves its keys as written, and PostgreSQL folds an unquoted `cte.firstName` to `firstname`.
|
|
57
|
+
* Strings are kept as is.
|
|
55
58
|
*/
|
|
56
59
|
export declare function getTypedSelectionKey<Type extends ObjectLiteral>(builder: WhereExpressionBuilder, selection: KeyProxyCallback<Type> | string, useQuotes?: boolean): string | string[];
|
|
@@ -268,12 +268,20 @@ function getTypedSingleColumnKey(builder, callback, methodName, jsonOptions) {
|
|
|
268
268
|
return key;
|
|
269
269
|
}
|
|
270
270
|
exports.getTypedSingleColumnKey = getTypedSingleColumnKey;
|
|
271
|
+
// an alias the query doesn't know yet may still get metadata (a join added later), so it stays unquoted
|
|
272
|
+
function isAliasWithoutMetadata(queryBuilder, aliasName) {
|
|
273
|
+
const alias = aliasName === undefined ? undefined : findQueryAlias(queryBuilder, aliasName);
|
|
274
|
+
return alias !== undefined && !alias.hasMetadata;
|
|
275
|
+
}
|
|
271
276
|
/**
|
|
272
|
-
* Key for typed select / order / distinct on a SelectQueryBuilder.
|
|
277
|
+
* Key for typed select / order / distinct / group by on a SelectQueryBuilder.
|
|
273
278
|
*
|
|
274
279
|
* Without quotes it is `alias.propertyPath` (`user.name`, `images.url`, `p.address.city`),
|
|
275
280
|
* which TypeORM maps to the column itself. With `useQuotes` it is the quoted database column
|
|
276
|
-
* (`"t"."ticket_status"`), since TypeORM doesn't map quoted keys.
|
|
281
|
+
* (`"t"."ticket_status"`), since TypeORM doesn't map quoted keys. An alias of the query without
|
|
282
|
+
* metadata (a subquery or a CTE in FROM or a join) is quoted unless `useQuotes` is `false`:
|
|
283
|
+
* TypeORM leaves its keys as written, and PostgreSQL folds an unquoted `cte.firstName` to `firstname`.
|
|
284
|
+
* Strings are kept as is.
|
|
277
285
|
*/
|
|
278
286
|
function getTypedSelectionKey(builder, selection, useQuotes) {
|
|
279
287
|
if (typeof selection === 'string') {
|
|
@@ -286,7 +294,7 @@ function getTypedSelectionKey(builder, selection, useQuotes) {
|
|
|
286
294
|
throw new TypeError(`Typed key "${keyHolder.getKeys().join('.')}" points into the JSON column "${resolved.propertyPath}": ` +
|
|
287
295
|
`select, order, distinct and group by take columns only. For an expression use tableHelper().jsonColumn()`);
|
|
288
296
|
}
|
|
289
|
-
if (useQuotes) {
|
|
297
|
+
if (useQuotes !== null && useQuotes !== void 0 ? useQuotes : isAliasWithoutMetadata(queryBuilder, resolved.aliasName)) {
|
|
290
298
|
return toQuotedColumnKey(queryBuilder, resolved);
|
|
291
299
|
}
|
|
292
300
|
return resolved.aliasName === undefined
|