typeorm-extensions 2.2.0-rc.1 → 2.2.0-rc.11

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.
Files changed (115) hide show
  1. package/README.md +70 -39
  2. package/dist/decorators/calculated-column.decorator.d.ts +7 -3
  3. package/dist/decorators/calculated-column.decorator.js +35 -6
  4. package/dist/decorators/generated-column.decorator.d.ts +17 -0
  5. package/dist/decorators/generated-column.decorator.js +15 -0
  6. package/dist/decorators/index.d.ts +1 -0
  7. package/dist/decorators/index.js +1 -0
  8. package/dist/extensions/calculated-column.extension.d.ts +3 -3
  9. package/dist/extensions/calculated-column.extension.js +3 -16
  10. package/dist/extensions/cursor-pagination.extension.d.ts +15 -2
  11. package/dist/extensions/cursor-pagination.extension.js +90 -13
  12. package/dist/extensions/get-many-with-totals.extension.js +12 -31
  13. package/dist/extensions/join-lateral.extension.js +4 -6
  14. package/dist/extensions/order.extension.d.ts +2 -2
  15. package/dist/extensions/pagination.extension.d.ts +7 -1
  16. package/dist/extensions/pagination.extension.js +5 -12
  17. package/dist/extensions/period-filter.extension.d.ts +4 -0
  18. package/dist/extensions/period-filter.extension.js +1 -9
  19. package/dist/extensions/typed/index.d.ts +2 -0
  20. package/dist/extensions/typed/index.js +2 -0
  21. package/dist/extensions/typed/typed-calculated/typed-calculated-column.extension.d.ts +19 -0
  22. package/dist/extensions/typed/typed-calculated/typed-calculated-column.extension.js +17 -0
  23. package/dist/extensions/typed/typed-distinct/typed-distinct.extension.d.ts +6 -4
  24. package/dist/extensions/typed/typed-distinct/typed-distinct.extension.js +9 -2
  25. package/dist/extensions/typed/typed-group-by/typed-group-by.extension.d.ts +8 -7
  26. package/dist/extensions/typed/typed-group-by/typed-group-by.extension.js +1 -1
  27. package/dist/extensions/typed/typed-having/typed-having.extension.d.ts +4 -4
  28. package/dist/extensions/typed/typed-having/typed-having.extension.js +1 -1
  29. package/dist/extensions/typed/typed-joins/typed-join-and-map.extension.d.ts +19 -0
  30. package/dist/extensions/typed/typed-joins/typed-join-and-map.extension.js +23 -0
  31. package/dist/extensions/typed/typed-joins/typed-joins.extension.d.ts +4 -4
  32. package/dist/extensions/typed/typed-joins/typed-joins.extension.js +11 -22
  33. package/dist/extensions/typed/typed-order-by/typed-order-by-array-position.extension.d.ts +2 -2
  34. package/dist/extensions/typed/typed-order-by/typed-order-by.extension.d.ts +4 -2
  35. package/dist/extensions/typed/typed-order-by/typed-order-by.extension.js +18 -17
  36. package/dist/extensions/typed/typed-returning/typed-returning.extension.js +1 -9
  37. package/dist/extensions/typed/typed-root.extension.d.ts +26 -4
  38. package/dist/extensions/typed/typed-select/typed-select.extension.d.ts +6 -6
  39. package/dist/extensions/typed/typed-select/typed-select.extension.js +3 -9
  40. package/dist/extensions/typed/typed-where/typed-period-filter.extension.d.ts +5 -1
  41. package/dist/extensions/typed/typed-where/typed-period-filter.extension.js +1 -9
  42. package/dist/extensions/typed/typed-where/typed-where-array.extension.d.ts +13 -9
  43. package/dist/extensions/typed/typed-where/typed-where-array.extension.js +4 -16
  44. package/dist/extensions/typed/typed-where/typed-where-ilike.extension.d.ts +10 -6
  45. package/dist/extensions/typed/typed-where/typed-where-ilike.extension.js +1 -9
  46. package/dist/extensions/typed/typed-where/typed-where-is-any.extension.d.ts +10 -6
  47. package/dist/extensions/typed/typed-where/typed-where-is-any.extension.js +3 -20
  48. package/dist/extensions/typed/typed-where/typed-where-is-distinct-from.extension.d.ts +10 -6
  49. package/dist/extensions/typed/typed-where/typed-where-is-distinct-from.extension.js +3 -20
  50. package/dist/extensions/typed/typed-where/typed-where-is-in.extension.d.ts +10 -6
  51. package/dist/extensions/typed/typed-where/typed-where-is-in.extension.js +3 -21
  52. package/dist/extensions/typed/typed-where/typed-where-json.extension.d.ts +10 -6
  53. package/dist/extensions/typed/typed-where/typed-where-json.extension.js +4 -21
  54. package/dist/extensions/typed/typed-where/typed-where-lower.extension.d.ts +10 -6
  55. package/dist/extensions/typed/typed-where/typed-where-lower.extension.js +1 -9
  56. package/dist/extensions/typed/typed-where/typed-where-similar.extension.d.ts +8 -4
  57. package/dist/extensions/typed/typed-where/typed-where-similar.extension.js +1 -8
  58. package/dist/extensions/typed/typed-where/typed-where.extension.d.ts +7 -3
  59. package/dist/extensions/typed/typed-where/typed-where.extension.js +2 -10
  60. package/dist/extensions/union.extension.js +1 -1
  61. package/dist/extensions/where-array.extension.d.ts +4 -0
  62. package/dist/extensions/where-array.extension.js +1 -9
  63. package/dist/extensions/where-exists.extension.js +4 -15
  64. package/dist/extensions/where-is-any.extension.d.ts +41 -128
  65. package/dist/extensions/where-is-any.extension.js +1 -9
  66. package/dist/extensions/where-is-distinct-from.extension.d.ts +4 -0
  67. package/dist/extensions/where-is-distinct-from.extension.js +1 -9
  68. package/dist/extensions/where-is-in.extension.d.ts +38 -116
  69. package/dist/extensions/where-is-in.extension.js +11 -27
  70. package/dist/extensions/where-json.extension.d.ts +4 -0
  71. package/dist/extensions/where-json.extension.js +1 -9
  72. package/dist/extensions/where-relation-exists.extension.d.ts +6 -6
  73. package/dist/extensions/where-relation-exists.extension.js +5 -25
  74. package/dist/helpers.d.ts +5 -0
  75. package/dist/helpers.js +12 -3
  76. package/dist/index.d.ts +1 -2
  77. package/dist/index.js +1 -4
  78. package/dist/types/extensions/cursor-pagination.types.d.ts +16 -1
  79. package/dist/types/extensions/get-many-with-totals.types.d.ts +4 -0
  80. package/dist/types/extensions/index.d.ts +1 -0
  81. package/dist/types/extensions/index.js +1 -0
  82. package/dist/types/extensions/typed-group-by.types.d.ts +2 -2
  83. package/dist/types/extensions/typed-join-and-map.types.d.ts +6 -0
  84. package/dist/types/extensions/typed-join-and-map.types.js +2 -0
  85. package/dist/types/interfaces/cursor-pagination.interface.d.ts +11 -0
  86. package/dist/types/modules/typed-root.types.d.ts +11 -9
  87. package/dist/utils/calculated-column.utils.d.ts +11 -0
  88. package/dist/utils/calculated-column.utils.js +33 -4
  89. package/dist/utils/common.utils.d.ts +2 -0
  90. package/dist/utils/common.utils.js +4 -1
  91. package/dist/utils/cursor.utils.d.ts +5 -0
  92. package/dist/utils/cursor.utils.js +18 -7
  93. package/dist/utils/json-path.utils.js +2 -2
  94. package/dist/utils/pagination.utils.d.ts +10 -0
  95. package/dist/utils/pagination.utils.js +27 -10
  96. package/dist/utils/parameter.utils.d.ts +10 -0
  97. package/dist/utils/parameter.utils.js +22 -1
  98. package/dist/utils/period.utils.js +2 -1
  99. package/dist/utils/prototype.utils.d.ts +9 -0
  100. package/dist/utils/prototype.utils.js +12 -2
  101. package/dist/utils/query-builder.utils.d.ts +43 -4
  102. package/dist/utils/query-builder.utils.js +239 -36
  103. package/dist/utils/reserved-qualifier-guard.utils.d.ts +36 -0
  104. package/dist/utils/reserved-qualifier-guard.utils.js +98 -0
  105. package/dist/utils/reserved-qualifier.utils.d.ts +33 -0
  106. package/dist/utils/reserved-qualifier.utils.js +252 -0
  107. package/dist/utils/table.utils.d.ts +27 -11
  108. package/dist/utils/table.utils.js +58 -23
  109. package/dist/utils/time-zone.utils.d.ts +8 -0
  110. package/dist/utils/time-zone.utils.js +15 -5
  111. package/dist/utils/typed-where.utils.d.ts +9 -0
  112. package/dist/utils/typed-where.utils.js +17 -0
  113. package/dist/utils/where.utils.d.ts +2 -0
  114. package/dist/utils/where.utils.js +21 -14
  115. package/package.json +2 -2
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const typeorm_1 = require("typeorm");
4
3
  const query_builder_utils_1 = require("../../../utils/query-builder.utils");
5
4
  const prototype_utils_1 = require("../../../utils/prototype.utils");
6
5
  const sql_utils_1 = require("../../../utils/sql.utils");
@@ -55,14 +54,7 @@ const extension = {
55
54
  orWhereIsInLowerTyped: createWhereIsInLowerTypedMethod('orWhere'),
56
55
  },
57
56
  };
58
- const queryBuilders = [
59
- typeorm_1.SelectQueryBuilder,
60
- typeorm_1.UpdateQueryBuilder,
61
- typeorm_1.DeleteQueryBuilder,
62
- ];
63
- queryBuilders.forEach((builder) => {
64
- (0, prototype_utils_1.patchPrototype)(builder, extension);
65
- });
57
+ (0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, extension);
66
58
  // implementation
67
59
  const lower = (sql) => `LOWER(${sql})`;
68
60
  /**
@@ -14,17 +14,17 @@ export interface TypedWhereSimilarMethods<Entity extends ObjectLiteral> {
14
14
  * If you had previously WHERE expression defined,
15
15
  * calling this function will override previously set WHERE conditions.
16
16
  */
17
- whereSimilarTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, term: string | null | undefined, options?: TypedSimilarOptions): this;
17
+ whereSimilarTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, term: string | null | undefined, options?: TypedSimilarOptions): this;
18
18
  /**
19
19
  * Adds new AND WHERE `column % :term` condition in the query builder (PostgreSQL, pg_trgm).
20
20
  * A blank term adds no condition.
21
21
  */
22
- andWhereSimilarTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, term: string | null | undefined, options?: TypedSimilarOptions): this;
22
+ andWhereSimilarTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, term: string | null | undefined, options?: TypedSimilarOptions): this;
23
23
  /**
24
24
  * Adds new OR WHERE `column % :term` condition in the query builder (PostgreSQL, pg_trgm).
25
25
  * A blank term adds no condition.
26
26
  */
27
- orWhereSimilarTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, term: string | null | undefined, options?: TypedSimilarOptions): this;
27
+ orWhereSimilarTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, term: string | null | undefined, options?: TypedSimilarOptions): this;
28
28
  }
29
29
  /** Trigram similarity score selection (PostgreSQL, `pg_trgm` extension). */
30
30
  export interface TypedSimilarityScoreMethods<Entity extends ObjectLiteral> {
@@ -35,7 +35,7 @@ export interface TypedSimilarityScoreMethods<Entity extends ObjectLiteral> {
35
35
  * (`word_similarity(:term, column)`, the score of `column %> :term`).
36
36
  * Use a lower-case alias: PostgreSQL folds an unquoted alias in ORDER BY.
37
37
  */
38
- addSimilarityScoreTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(selection: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, term: string | null | undefined, alias: string, options?: SimilarityScoreOptions): this;
38
+ addSimilarityScoreTyped<Type extends ObjectLiteral = TypedRoot<Entity, this>>(selection: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, term: string | null | undefined, alias: string, options?: SimilarityScoreOptions): this;
39
39
  }
40
40
  declare module 'typeorm/query-builder/WhereExpressionBuilder' {
41
41
  interface WhereExpressionBuilder extends TypedWhereSimilarMethods<ObjectLiteral> {
@@ -53,3 +53,7 @@ declare module 'typeorm/query-builder/DeleteQueryBuilder' {
53
53
  interface DeleteQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereSimilarMethods<Entity> {
54
54
  }
55
55
  }
56
+ declare module 'typeorm/query-builder/SoftDeleteQueryBuilder' {
57
+ interface SoftDeleteQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereSimilarMethods<Entity> {
58
+ }
59
+ }
@@ -62,12 +62,5 @@ const scoreExtension = {
62
62
  },
63
63
  },
64
64
  };
65
- const queryBuilders = [
66
- typeorm_1.SelectQueryBuilder,
67
- typeorm_1.UpdateQueryBuilder,
68
- typeorm_1.DeleteQueryBuilder,
69
- ];
70
- queryBuilders.forEach((builder) => {
71
- (0, prototype_utils_1.patchPrototype)(builder, extension);
72
- });
65
+ (0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, extension);
73
66
  (0, prototype_utils_1.patchPrototype)(typeorm_1.SelectQueryBuilder, scoreExtension);
@@ -14,17 +14,17 @@ export interface TypedWhereMethods<Entity extends ObjectLiteral> {
14
14
  * calling this function will override previously set WHERE conditions.
15
15
  * Additionally you can add parameters used in where expression.
16
16
  */
17
- whereTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType, Operator extends string = string>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity>>>) => Value, conditions: Operator, ...args: TypedWhereArgs<Type, Operator, Value>): this;
17
+ whereTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType, Operator extends string = string>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity, this>>>) => Value, conditions: Operator, ...args: TypedWhereArgs<Type, Operator, Value>): this;
18
18
  /**
19
19
  * Adds new AND WHERE condition in the query builder.
20
20
  * Additionally you can add parameters used in where expression.
21
21
  */
22
- andWhereTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType, Operator extends string = string>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity>>>) => Value, conditions: Operator, ...args: TypedWhereArgs<Type, Operator, Value>): this;
22
+ andWhereTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType, Operator extends string = string>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity, this>>>) => Value, conditions: Operator, ...args: TypedWhereArgs<Type, Operator, Value>): this;
23
23
  /**
24
24
  * Adds new OR WHERE condition in the query builder.
25
25
  * Additionally you can add parameters used in where expression.
26
26
  */
27
- orWhereTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType, Operator extends string = string>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity>>>) => Value, conditions: Operator, ...args: TypedWhereArgs<Type, Operator, Value>): this;
27
+ orWhereTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType, Operator extends string = string>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity, this>>>) => Value, conditions: Operator, ...args: TypedWhereArgs<Type, Operator, Value>): this;
28
28
  }
29
29
  declare module 'typeorm/query-builder/WhereExpressionBuilder' {
30
30
  interface WhereExpressionBuilder extends TypedWhereMethods<ObjectLiteral> {
@@ -42,3 +42,7 @@ declare module 'typeorm/query-builder/DeleteQueryBuilder' {
42
42
  interface DeleteQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereMethods<Entity> {
43
43
  }
44
44
  }
45
+ declare module 'typeorm/query-builder/SoftDeleteQueryBuilder' {
46
+ interface SoftDeleteQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereMethods<Entity> {
47
+ }
48
+ }
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const typeorm_1 = require("typeorm");
4
3
  const query_builder_utils_1 = require("../../../utils/query-builder.utils");
5
4
  const prototype_utils_1 = require("../../../utils/prototype.utils");
6
5
  const where_utils_1 = require("../../../utils/where.utils");
@@ -16,21 +15,14 @@ const extension = {
16
15
  orWhereTyped: createWhereTypedMethod('orWhere'),
17
16
  },
18
17
  };
19
- const queryBuilders = [
20
- typeorm_1.SelectQueryBuilder,
21
- typeorm_1.UpdateQueryBuilder,
22
- typeorm_1.DeleteQueryBuilder,
23
- ];
24
- queryBuilders.forEach((builder) => {
25
- (0, prototype_utils_1.patchPrototype)(builder, extension);
26
- });
18
+ (0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, extension);
27
19
  // implementation
28
20
  function attachTypedWhere(builder, method, where, conditions, parameters, options) {
29
21
  const { addValue } = options || {};
30
22
  if (typeof where === 'function') {
31
23
  // several columns have no single meaning (AND? OR?), and `where…` kept only the last one
32
24
  // a path into a JSON column is cast to the type of the value it is compared with
33
- const value = (0, where_utils_1.isParamsObject)(parameters) ? Object.values(parameters)[0] : parameters;
25
+ const value = (0, where_utils_1.getComparedValue)(parameters);
34
26
  const key = (0, query_builder_utils_1.getTypedSingleColumnKey)(builder, where, `${method}Typed`, { value });
35
27
  return (0, where_utils_1.attachWhere)(builder, method, key, conditions, parameters, {
36
28
  addValue,
@@ -46,7 +46,7 @@ function ordersOrLimits(query, sql) {
46
46
  return Object.keys(allOrderBys !== null && allOrderBys !== void 0 ? allOrderBys : {}).length > 0 || [limit, offset, take, skip].some((value) => value !== undefined);
47
47
  }
48
48
  function bindParameters(builder, query) {
49
- const [sql, parameters] = (0, parameter_utils_1.withUniqueParameterNames)(query.getQuery(), query.getParameters());
49
+ const [sql, parameters] = (0, parameter_utils_1.toSubQuerySql)(query);
50
50
  builder.setParameters(parameters);
51
51
  return sql;
52
52
  }
@@ -68,3 +68,7 @@ declare module 'typeorm/query-builder/DeleteQueryBuilder' {
68
68
  interface DeleteQueryBuilder<Entity extends ObjectLiteral> extends WhereArrayMethods {
69
69
  }
70
70
  }
71
+ declare module 'typeorm/query-builder/SoftDeleteQueryBuilder' {
72
+ interface SoftDeleteQueryBuilder<Entity extends ObjectLiteral> extends WhereArrayMethods {
73
+ }
74
+ }
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const typeorm_1 = require("typeorm");
4
3
  const prototype_utils_1 = require("../utils/prototype.utils");
5
4
  const query_builder_utils_1 = require("../utils/query-builder.utils");
6
5
  const sql_utils_1 = require("../utils/sql.utils");
@@ -20,14 +19,7 @@ const extension = {
20
19
  orWhereArrayOverlaps: createWhereArrayMethod('orWhere', '&&'),
21
20
  },
22
21
  };
23
- const queryBuilders = [
24
- typeorm_1.SelectQueryBuilder,
25
- typeorm_1.UpdateQueryBuilder,
26
- typeorm_1.DeleteQueryBuilder,
27
- ];
28
- queryBuilders.forEach((builder) => {
29
- (0, prototype_utils_1.patchPrototype)(builder, extension);
30
- });
22
+ (0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, extension);
31
23
  // implementation
32
24
  function attachWhereArray(builder, method, field, operator, values, arrayType) {
33
25
  if (!method || typeof field !== 'string') {
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.attachExists = void 0;
4
- const typeorm_1 = require("typeorm");
5
- const SoftDeleteQueryBuilder_1 = require("typeorm/query-builder/SoftDeleteQueryBuilder");
6
4
  const prototype_utils_1 = require("../utils/prototype.utils");
7
5
  const parameter_utils_1 = require("../utils/parameter.utils");
6
+ const query_builder_utils_1 = require("../utils/query-builder.utils");
8
7
  const existsMethods = {
9
8
  prototype: {
10
9
  whereExists(subQuery) {
@@ -33,10 +32,8 @@ const notExistsMethods = {
33
32
  };
34
33
  // only where the builder lacks them: SelectQueryBuilder keeps TypeORM's own whereExists /
35
34
  // andWhereExists / orWhereExists, and a later TypeORM that adds any of these keeps its own
36
- [typeorm_1.SelectQueryBuilder, typeorm_1.UpdateQueryBuilder, typeorm_1.DeleteQueryBuilder, SoftDeleteQueryBuilder_1.SoftDeleteQueryBuilder].forEach((builder) => {
37
- (0, prototype_utils_1.patchPrototype)(builder, existsMethods, { onlyMissing: true });
38
- (0, prototype_utils_1.patchPrototype)(builder, notExistsMethods, { onlyMissing: true });
39
- });
35
+ (0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, existsMethods, { onlyMissing: true });
36
+ (0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, notExistsMethods, { onlyMissing: true });
40
37
  // implementation
41
38
  function attachExists(builder, method, subQuery, negate) {
42
39
  const [condition, parameters] = (0, parameter_utils_1.withUniqueParameterNames)(...getExistsCondition(subQuery));
@@ -48,15 +45,7 @@ exports.attachExists = attachExists;
48
45
  * drops GROUP BY, which leaves a HAVING to aggregate the whole subquery: the GROUP BY stays with one.
49
46
  */
50
47
  function getExistsCondition(subQuery) {
51
- const query = subQuery
52
- .clone()
53
- .orderBy()
54
- .offset(undefined)
55
- .limit(undefined)
56
- .skip(undefined)
57
- .take(undefined)
58
- .select('1')
59
- .setOption('disable-global-order');
48
+ const query = (0, query_builder_utils_1.withoutPaging)(subQuery.clone()).select('1');
60
49
  if (query.expressionMap.havings.length === 0) {
61
50
  query.groupBy();
62
51
  }
@@ -1,142 +1,55 @@
1
1
  import { ObjectLiteral } from 'typeorm';
2
2
  import { ArgsType } from '../types/util-types';
3
+ export interface WhereIsAnyMethods {
4
+ /**
5
+ * Sets WHERE `field = ANY(:array)` condition in the query builder (PostgreSQL).
6
+ * The array is bound as a single parameter instead of one parameter per value.
7
+ * `arrayType` (e.g. `'uuid[]'`) casts the parameter: `= ANY(CAST(:array AS uuid[]))`.
8
+ * If you had previously WHERE expression defined,
9
+ * calling this function will override previously set WHERE conditions.
10
+ */
11
+ whereIsAny(field: string, array?: ArgsType, arrayType?: string): this;
12
+ /**
13
+ * Adds new AND WHERE `field = ANY(:array)` condition in the query builder (PostgreSQL).
14
+ */
15
+ andWhereIsAny(field: string, array?: ArgsType, arrayType?: string): this;
16
+ /**
17
+ * Adds new OR WHERE `field = ANY(:array)` condition in the query builder (PostgreSQL).
18
+ */
19
+ orWhereIsAny(field: string, array?: ArgsType, arrayType?: string): this;
20
+ /**
21
+ * Sets WHERE `field <> ALL(:array)` condition in the query builder (PostgreSQL):
22
+ * the field differs from every value of the array.
23
+ * If you had previously WHERE expression defined,
24
+ * calling this function will override previously set WHERE conditions.
25
+ */
26
+ whereIsNotAny(field: string, array?: ArgsType, arrayType?: string): this;
27
+ /**
28
+ * Adds new AND WHERE `field <> ALL(:array)` condition in the query builder (PostgreSQL).
29
+ */
30
+ andWhereIsNotAny(field: string, array?: ArgsType, arrayType?: string): this;
31
+ /**
32
+ * Adds new OR WHERE `field <> ALL(:array)` condition in the query builder (PostgreSQL).
33
+ */
34
+ orWhereIsNotAny(field: string, array?: ArgsType, arrayType?: string): this;
35
+ }
3
36
  declare module 'typeorm/query-builder/WhereExpressionBuilder' {
4
- interface WhereExpressionBuilder {
5
- /**
6
- * Sets WHERE `field = ANY(:array)` condition in the query builder (PostgreSQL).
7
- * The array is bound as a single parameter instead of one parameter per value.
8
- * `arrayType` (e.g. `'uuid[]'`) casts the parameter: `= ANY(CAST(:array AS uuid[]))`.
9
- * If you had previously WHERE expression defined,
10
- * calling this function will override previously set WHERE conditions.
11
- */
12
- whereIsAny(field: string, array?: ArgsType, arrayType?: string): this;
13
- /**
14
- * Adds new AND WHERE `field = ANY(:array)` condition in the query builder (PostgreSQL).
15
- */
16
- andWhereIsAny(field: string, array?: ArgsType, arrayType?: string): this;
17
- /**
18
- * Adds new OR WHERE `field = ANY(:array)` condition in the query builder (PostgreSQL).
19
- */
20
- orWhereIsAny(field: string, array?: ArgsType, arrayType?: string): this;
21
- /**
22
- * Sets WHERE `field <> ALL(:array)` condition in the query builder (PostgreSQL):
23
- * the field differs from every value of the array.
24
- * If you had previously WHERE expression defined,
25
- * calling this function will override previously set WHERE conditions.
26
- */
27
- whereIsNotAny(field: string, array?: ArgsType, arrayType?: string): this;
28
- /**
29
- * Adds new AND WHERE `field <> ALL(:array)` condition in the query builder (PostgreSQL).
30
- */
31
- andWhereIsNotAny(field: string, array?: ArgsType, arrayType?: string): this;
32
- /**
33
- * Adds new OR WHERE `field <> ALL(:array)` condition in the query builder (PostgreSQL).
34
- */
35
- orWhereIsNotAny(field: string, array?: ArgsType, arrayType?: string): this;
37
+ interface WhereExpressionBuilder extends WhereIsAnyMethods {
36
38
  }
37
39
  }
38
40
  declare module 'typeorm/query-builder/SelectQueryBuilder' {
39
- interface SelectQueryBuilder<Entity extends ObjectLiteral> {
40
- /**
41
- * Sets WHERE `field = ANY(:array)` condition in the query builder (PostgreSQL).
42
- * The array is bound as a single parameter instead of one parameter per value.
43
- * `arrayType` (e.g. `'uuid[]'`) casts the parameter: `= ANY(CAST(:array AS uuid[]))`.
44
- * If you had previously WHERE expression defined,
45
- * calling this function will override previously set WHERE conditions.
46
- */
47
- whereIsAny(field: string, array?: ArgsType, arrayType?: string): SelectQueryBuilder<Entity>;
48
- /**
49
- * Adds new AND WHERE `field = ANY(:array)` condition in the query builder (PostgreSQL).
50
- */
51
- andWhereIsAny(field: string, array?: ArgsType, arrayType?: string): SelectQueryBuilder<Entity>;
52
- /**
53
- * Adds new OR WHERE `field = ANY(:array)` condition in the query builder (PostgreSQL).
54
- */
55
- orWhereIsAny(field: string, array?: ArgsType, arrayType?: string): SelectQueryBuilder<Entity>;
56
- /**
57
- * Sets WHERE `field <> ALL(:array)` condition in the query builder (PostgreSQL):
58
- * the field differs from every value of the array.
59
- * If you had previously WHERE expression defined,
60
- * calling this function will override previously set WHERE conditions.
61
- */
62
- whereIsNotAny(field: string, array?: ArgsType, arrayType?: string): SelectQueryBuilder<Entity>;
63
- /**
64
- * Adds new AND WHERE `field <> ALL(:array)` condition in the query builder (PostgreSQL).
65
- */
66
- andWhereIsNotAny(field: string, array?: ArgsType, arrayType?: string): SelectQueryBuilder<Entity>;
67
- /**
68
- * Adds new OR WHERE `field <> ALL(:array)` condition in the query builder (PostgreSQL).
69
- */
70
- orWhereIsNotAny(field: string, array?: ArgsType, arrayType?: string): SelectQueryBuilder<Entity>;
41
+ interface SelectQueryBuilder<Entity extends ObjectLiteral> extends WhereIsAnyMethods {
71
42
  }
72
43
  }
73
44
  declare module 'typeorm/query-builder/UpdateQueryBuilder' {
74
- interface UpdateQueryBuilder<Entity extends ObjectLiteral> {
75
- /**
76
- * Sets WHERE `field = ANY(:array)` condition in the query builder (PostgreSQL).
77
- * The array is bound as a single parameter instead of one parameter per value.
78
- * `arrayType` (e.g. `'uuid[]'`) casts the parameter: `= ANY(CAST(:array AS uuid[]))`.
79
- * If you had previously WHERE expression defined,
80
- * calling this function will override previously set WHERE conditions.
81
- */
82
- whereIsAny(field: string, array?: ArgsType, arrayType?: string): UpdateQueryBuilder<Entity>;
83
- /**
84
- * Adds new AND WHERE `field = ANY(:array)` condition in the query builder (PostgreSQL).
85
- */
86
- andWhereIsAny(field: string, array?: ArgsType, arrayType?: string): UpdateQueryBuilder<Entity>;
87
- /**
88
- * Adds new OR WHERE `field = ANY(:array)` condition in the query builder (PostgreSQL).
89
- */
90
- orWhereIsAny(field: string, array?: ArgsType, arrayType?: string): UpdateQueryBuilder<Entity>;
91
- /**
92
- * Sets WHERE `field <> ALL(:array)` condition in the query builder (PostgreSQL):
93
- * the field differs from every value of the array.
94
- * If you had previously WHERE expression defined,
95
- * calling this function will override previously set WHERE conditions.
96
- */
97
- whereIsNotAny(field: string, array?: ArgsType, arrayType?: string): UpdateQueryBuilder<Entity>;
98
- /**
99
- * Adds new AND WHERE `field <> ALL(:array)` condition in the query builder (PostgreSQL).
100
- */
101
- andWhereIsNotAny(field: string, array?: ArgsType, arrayType?: string): UpdateQueryBuilder<Entity>;
102
- /**
103
- * Adds new OR WHERE `field <> ALL(:array)` condition in the query builder (PostgreSQL).
104
- */
105
- orWhereIsNotAny(field: string, array?: ArgsType, arrayType?: string): UpdateQueryBuilder<Entity>;
45
+ interface UpdateQueryBuilder<Entity extends ObjectLiteral> extends WhereIsAnyMethods {
106
46
  }
107
47
  }
108
48
  declare module 'typeorm/query-builder/DeleteQueryBuilder' {
109
- interface DeleteQueryBuilder<Entity extends ObjectLiteral> {
110
- /**
111
- * Sets WHERE `field = ANY(:array)` condition in the query builder (PostgreSQL).
112
- * The array is bound as a single parameter instead of one parameter per value.
113
- * `arrayType` (e.g. `'uuid[]'`) casts the parameter: `= ANY(CAST(:array AS uuid[]))`.
114
- * If you had previously WHERE expression defined,
115
- * calling this function will override previously set WHERE conditions.
116
- */
117
- whereIsAny(field: string, array?: ArgsType, arrayType?: string): DeleteQueryBuilder<Entity>;
118
- /**
119
- * Adds new AND WHERE `field = ANY(:array)` condition in the query builder (PostgreSQL).
120
- */
121
- andWhereIsAny(field: string, array?: ArgsType, arrayType?: string): DeleteQueryBuilder<Entity>;
122
- /**
123
- * Adds new OR WHERE `field = ANY(:array)` condition in the query builder (PostgreSQL).
124
- */
125
- orWhereIsAny(field: string, array?: ArgsType, arrayType?: string): DeleteQueryBuilder<Entity>;
126
- /**
127
- * Sets WHERE `field <> ALL(:array)` condition in the query builder (PostgreSQL):
128
- * the field differs from every value of the array.
129
- * If you had previously WHERE expression defined,
130
- * calling this function will override previously set WHERE conditions.
131
- */
132
- whereIsNotAny(field: string, array?: ArgsType, arrayType?: string): DeleteQueryBuilder<Entity>;
133
- /**
134
- * Adds new AND WHERE `field <> ALL(:array)` condition in the query builder (PostgreSQL).
135
- */
136
- andWhereIsNotAny(field: string, array?: ArgsType, arrayType?: string): DeleteQueryBuilder<Entity>;
137
- /**
138
- * Adds new OR WHERE `field <> ALL(:array)` condition in the query builder (PostgreSQL).
139
- */
140
- orWhereIsNotAny(field: string, array?: ArgsType, arrayType?: string): DeleteQueryBuilder<Entity>;
49
+ interface DeleteQueryBuilder<Entity extends ObjectLiteral> extends WhereIsAnyMethods {
50
+ }
51
+ }
52
+ declare module 'typeorm/query-builder/SoftDeleteQueryBuilder' {
53
+ interface SoftDeleteQueryBuilder<Entity extends ObjectLiteral> extends WhereIsAnyMethods {
141
54
  }
142
55
  }
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const typeorm_1 = require("typeorm");
4
3
  const prototype_utils_1 = require("../utils/prototype.utils");
5
4
  const query_builder_utils_1 = require("../utils/query-builder.utils");
6
5
  const sql_utils_1 = require("../utils/sql.utils");
@@ -17,14 +16,7 @@ const extension = {
17
16
  orWhereIsNotAny: createWhereIsAnyMethod('orWhere', '<> ALL'),
18
17
  },
19
18
  };
20
- const queryBuilders = [
21
- typeorm_1.SelectQueryBuilder,
22
- typeorm_1.UpdateQueryBuilder,
23
- typeorm_1.DeleteQueryBuilder,
24
- ];
25
- queryBuilders.forEach((builder) => {
26
- (0, prototype_utils_1.patchPrototype)(builder, extension);
27
- });
19
+ (0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, extension);
28
20
  // implementation
29
21
  function attachWhereIsAny(builder, method, field, comparison, array, arrayType) {
30
22
  if (!method || typeof field !== 'string') {
@@ -54,3 +54,7 @@ declare module 'typeorm/query-builder/DeleteQueryBuilder' {
54
54
  interface DeleteQueryBuilder<Entity extends ObjectLiteral> extends WhereDistinctMethods {
55
55
  }
56
56
  }
57
+ declare module 'typeorm/query-builder/SoftDeleteQueryBuilder' {
58
+ interface SoftDeleteQueryBuilder<Entity extends ObjectLiteral> extends WhereDistinctMethods {
59
+ }
60
+ }
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const typeorm_1 = require("typeorm");
4
3
  const prototype_utils_1 = require("../utils/prototype.utils");
5
4
  const query_builder_utils_1 = require("../utils/query-builder.utils");
6
5
  const sql_utils_1 = require("../utils/sql.utils");
@@ -19,14 +18,7 @@ const extension = {
19
18
  orWhereIsNotDistinctFrom: createWhereDistinctMethod('orWhere', false),
20
19
  },
21
20
  };
22
- const queryBuilders = [
23
- typeorm_1.SelectQueryBuilder,
24
- typeorm_1.UpdateQueryBuilder,
25
- typeorm_1.DeleteQueryBuilder,
26
- ];
27
- queryBuilders.forEach((builder) => {
28
- (0, prototype_utils_1.patchPrototype)(builder, extension);
29
- });
21
+ (0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, extension);
30
22
  // implementation
31
23
  /** `field IS [NOT] DISTINCT FROM value` in the database's own null-safe syntax. */
32
24
  function buildDistinctCondition(driver, field, distinct, value) {
@@ -1,130 +1,52 @@
1
1
  import { ObjectLiteral } from 'typeorm';
2
2
  import { ArgsType } from '../types/util-types';
3
+ export interface WhereIsInMethods {
4
+ /**
5
+ * Sets WHERE IN condition in the query builder.
6
+ * If you had previously WHERE expression defined,
7
+ * calling this function will override previously set WHERE conditions.
8
+ */
9
+ whereIsIn(field: string, array?: ArgsType): this;
10
+ /**
11
+ * Adds new AND WHERE IN condition in the query builder.
12
+ */
13
+ andWhereIsIn(field: string, array?: ArgsType): this;
14
+ /**
15
+ * Adds new OR WHERE IN condition in the query builder.
16
+ */
17
+ orWhereIsIn(field: string, array?: ArgsType): this;
18
+ /**
19
+ * Sets WHERE NOT IN condition in the query builder.
20
+ * If you had previously WHERE expression defined,
21
+ * calling this function will override previously set WHERE conditions.
22
+ */
23
+ whereIsNotIn(field: string, array?: ArgsType): this;
24
+ /**
25
+ * Adds new AND WHERE NOT IN condition in the query builder.
26
+ */
27
+ andWhereIsNotIn(field: string, array?: ArgsType): this;
28
+ /**
29
+ * Adds new OR WHERE NOT IN condition in the query builder.
30
+ */
31
+ orWhereIsNotIn(field: string, array?: ArgsType): this;
32
+ }
3
33
  declare module 'typeorm/query-builder/WhereExpressionBuilder' {
4
- interface WhereExpressionBuilder {
5
- /**
6
- * Sets WHERE IN condition in the query builder.
7
- * If you had previously WHERE expression defined,
8
- * calling this function will override previously set WHERE conditions.
9
- */
10
- whereIsIn(field: string, array?: ArgsType): this;
11
- /**
12
- * Adds new AND WHERE IN condition in the query builder.
13
- */
14
- andWhereIsIn(field: string, array?: ArgsType): this;
15
- /**
16
- * Adds new OR WHERE IN condition in the query builder.
17
- */
18
- orWhereIsIn(field: string, array?: ArgsType): this;
19
- /**
20
- * Sets WHERE NOT IN condition in the query builder.
21
- * If you had previously WHERE expression defined,
22
- * calling this function will override previously set WHERE conditions.
23
- */
24
- whereIsNotIn(field: string, array?: ArgsType): this;
25
- /**
26
- * Adds new AND WHERE NOT IN condition in the query builder.
27
- */
28
- andWhereIsNotIn(field: string, array?: ArgsType): this;
29
- /**
30
- * Adds new OR WHERE NOT IN condition in the query builder.
31
- */
32
- orWhereIsNotIn(field: string, array?: ArgsType): this;
34
+ interface WhereExpressionBuilder extends WhereIsInMethods {
33
35
  }
34
36
  }
35
37
  declare module 'typeorm/query-builder/SelectQueryBuilder' {
36
- interface SelectQueryBuilder<Entity extends ObjectLiteral> {
37
- /**
38
- * Sets WHERE IN condition in the query builder.
39
- * If you had previously WHERE expression defined,
40
- * calling this function will override previously set WHERE conditions.
41
- */
42
- whereIsIn(field: string, array?: ArgsType): SelectQueryBuilder<Entity>;
43
- /**
44
- * Adds new AND WHERE IN condition in the query builder.
45
- */
46
- andWhereIsIn(field: string, array?: ArgsType): SelectQueryBuilder<Entity>;
47
- /**
48
- * Adds new OR WHERE IN condition in the query builder.
49
- */
50
- orWhereIsIn(field: string, array?: ArgsType): SelectQueryBuilder<Entity>;
51
- /**
52
- * Sets WHERE NOT IN condition in the query builder.
53
- * If you had previously WHERE expression defined,
54
- * calling this function will override previously set WHERE conditions.
55
- */
56
- whereIsNotIn(field: string, array?: ArgsType): SelectQueryBuilder<Entity>;
57
- /**
58
- * Adds new AND WHERE NOT IN condition in the query builder.
59
- */
60
- andWhereIsNotIn(field: string, array?: ArgsType): SelectQueryBuilder<Entity>;
61
- /**
62
- * Adds new OR WHERE NOT IN condition in the query builder.
63
- */
64
- orWhereIsNotIn(field: string, array?: ArgsType): SelectQueryBuilder<Entity>;
38
+ interface SelectQueryBuilder<Entity extends ObjectLiteral> extends WhereIsInMethods {
65
39
  }
66
40
  }
67
41
  declare module 'typeorm/query-builder/UpdateQueryBuilder' {
68
- interface UpdateQueryBuilder<Entity extends ObjectLiteral> {
69
- /**
70
- * Sets WHERE IN condition in the query builder.
71
- * If you had previously WHERE expression defined,
72
- * calling this function will override previously set WHERE conditions.
73
- */
74
- whereIsIn(field: string, array?: ArgsType): UpdateQueryBuilder<Entity>;
75
- /**
76
- * Adds new AND WHERE IN condition in the query builder.
77
- */
78
- andWhereIsIn(field: string, array?: ArgsType): UpdateQueryBuilder<Entity>;
79
- /**
80
- * Adds new OR WHERE IN condition in the query builder.
81
- */
82
- orWhereIsIn(field: string, array?: ArgsType): UpdateQueryBuilder<Entity>;
83
- /**
84
- * Sets WHERE NOT IN condition in the query builder.
85
- * If you had previously WHERE expression defined,
86
- * calling this function will override previously set WHERE conditions.
87
- */
88
- whereIsNotIn(field: string, array?: ArgsType): UpdateQueryBuilder<Entity>;
89
- /**
90
- * Adds new AND WHERE NOT IN condition in the query builder.
91
- */
92
- andWhereIsNotIn(field: string, array?: ArgsType): UpdateQueryBuilder<Entity>;
93
- /**
94
- * Adds new OR WHERE NOT IN condition in the query builder.
95
- */
96
- orWhereIsNotIn(field: string, array?: ArgsType): UpdateQueryBuilder<Entity>;
42
+ interface UpdateQueryBuilder<Entity extends ObjectLiteral> extends WhereIsInMethods {
97
43
  }
98
44
  }
99
45
  declare module 'typeorm/query-builder/DeleteQueryBuilder' {
100
- interface DeleteQueryBuilder<Entity extends ObjectLiteral> {
101
- /**
102
- * Sets WHERE IN condition in the query builder.
103
- * If you had previously WHERE expression defined,
104
- * calling this function will override previously set WHERE conditions.
105
- */
106
- whereIsIn(field: string, array?: ArgsType): DeleteQueryBuilder<Entity>;
107
- /**
108
- * Adds new AND WHERE IN condition in the query builder.
109
- */
110
- andWhereIsIn(field: string, array?: ArgsType): DeleteQueryBuilder<Entity>;
111
- /**
112
- * Adds new OR WHERE IN condition in the query builder.
113
- */
114
- orWhereIsIn(field: string, array?: ArgsType): DeleteQueryBuilder<Entity>;
115
- /**
116
- * Sets WHERE NOT IN condition in the query builder.
117
- * If you had previously WHERE expression defined,
118
- * calling this function will override previously set WHERE conditions.
119
- */
120
- whereIsNotIn(field: string, array?: ArgsType): DeleteQueryBuilder<Entity>;
121
- /**
122
- * Adds new AND WHERE NOT IN condition in the query builder.
123
- */
124
- andWhereIsNotIn(field: string, array?: ArgsType): DeleteQueryBuilder<Entity>;
125
- /**
126
- * Adds new OR WHERE NOT IN condition in the query builder.
127
- */
128
- orWhereIsNotIn(field: string, array?: ArgsType): DeleteQueryBuilder<Entity>;
46
+ interface DeleteQueryBuilder<Entity extends ObjectLiteral> extends WhereIsInMethods {
47
+ }
48
+ }
49
+ declare module 'typeorm/query-builder/SoftDeleteQueryBuilder' {
50
+ interface SoftDeleteQueryBuilder<Entity extends ObjectLiteral> extends WhereIsInMethods {
129
51
  }
130
52
  }