typeorm-extensions 2.2.0-rc.0 → 2.2.0-rc.10

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 (112) 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 +2 -1
  11. package/dist/extensions/cursor-pagination.extension.js +7 -13
  12. package/dist/extensions/get-many-with-totals.extension.js +13 -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 +1 -1
  16. package/dist/extensions/period-filter.extension.d.ts +4 -0
  17. package/dist/extensions/period-filter.extension.js +1 -9
  18. package/dist/extensions/typed/index.d.ts +2 -0
  19. package/dist/extensions/typed/index.js +2 -0
  20. package/dist/extensions/typed/typed-calculated/typed-calculated-column.extension.d.ts +19 -0
  21. package/dist/extensions/typed/typed-calculated/typed-calculated-column.extension.js +17 -0
  22. package/dist/extensions/typed/typed-distinct/typed-distinct.extension.d.ts +6 -4
  23. package/dist/extensions/typed/typed-distinct/typed-distinct.extension.js +9 -2
  24. package/dist/extensions/typed/typed-group-by/typed-group-by.extension.d.ts +8 -7
  25. package/dist/extensions/typed/typed-group-by/typed-group-by.extension.js +1 -1
  26. package/dist/extensions/typed/typed-having/typed-having.extension.d.ts +4 -4
  27. package/dist/extensions/typed/typed-having/typed-having.extension.js +1 -1
  28. package/dist/extensions/typed/typed-joins/typed-join-and-map.extension.d.ts +19 -0
  29. package/dist/extensions/typed/typed-joins/typed-join-and-map.extension.js +23 -0
  30. package/dist/extensions/typed/typed-joins/typed-joins.extension.d.ts +4 -4
  31. package/dist/extensions/typed/typed-joins/typed-joins.extension.js +11 -22
  32. package/dist/extensions/typed/typed-order-by/typed-order-by-array-position.extension.d.ts +2 -2
  33. package/dist/extensions/typed/typed-order-by/typed-order-by.extension.d.ts +4 -2
  34. package/dist/extensions/typed/typed-order-by/typed-order-by.extension.js +18 -17
  35. package/dist/extensions/typed/typed-returning/typed-returning.extension.js +1 -9
  36. package/dist/extensions/typed/typed-root.extension.d.ts +26 -4
  37. package/dist/extensions/typed/typed-select/typed-select.extension.d.ts +6 -6
  38. package/dist/extensions/typed/typed-select/typed-select.extension.js +3 -9
  39. package/dist/extensions/typed/typed-where/typed-period-filter.extension.d.ts +5 -1
  40. package/dist/extensions/typed/typed-where/typed-period-filter.extension.js +1 -9
  41. package/dist/extensions/typed/typed-where/typed-where-array.extension.d.ts +13 -9
  42. package/dist/extensions/typed/typed-where/typed-where-array.extension.js +4 -16
  43. package/dist/extensions/typed/typed-where/typed-where-ilike.extension.d.ts +10 -6
  44. package/dist/extensions/typed/typed-where/typed-where-ilike.extension.js +1 -9
  45. package/dist/extensions/typed/typed-where/typed-where-is-any.extension.d.ts +10 -6
  46. package/dist/extensions/typed/typed-where/typed-where-is-any.extension.js +3 -20
  47. package/dist/extensions/typed/typed-where/typed-where-is-distinct-from.extension.d.ts +10 -6
  48. package/dist/extensions/typed/typed-where/typed-where-is-distinct-from.extension.js +3 -20
  49. package/dist/extensions/typed/typed-where/typed-where-is-in.extension.d.ts +10 -6
  50. package/dist/extensions/typed/typed-where/typed-where-is-in.extension.js +3 -21
  51. package/dist/extensions/typed/typed-where/typed-where-json.extension.d.ts +10 -6
  52. package/dist/extensions/typed/typed-where/typed-where-json.extension.js +4 -21
  53. package/dist/extensions/typed/typed-where/typed-where-lower.extension.d.ts +10 -6
  54. package/dist/extensions/typed/typed-where/typed-where-lower.extension.js +1 -9
  55. package/dist/extensions/typed/typed-where/typed-where-similar.extension.d.ts +8 -4
  56. package/dist/extensions/typed/typed-where/typed-where-similar.extension.js +1 -8
  57. package/dist/extensions/typed/typed-where/typed-where.extension.d.ts +7 -3
  58. package/dist/extensions/typed/typed-where/typed-where.extension.js +2 -10
  59. package/dist/extensions/union.extension.js +1 -1
  60. package/dist/extensions/where-array.extension.d.ts +4 -0
  61. package/dist/extensions/where-array.extension.js +1 -9
  62. package/dist/extensions/where-exists.extension.js +4 -15
  63. package/dist/extensions/where-is-any.extension.d.ts +41 -128
  64. package/dist/extensions/where-is-any.extension.js +1 -9
  65. package/dist/extensions/where-is-distinct-from.extension.d.ts +4 -0
  66. package/dist/extensions/where-is-distinct-from.extension.js +1 -9
  67. package/dist/extensions/where-is-in.extension.d.ts +38 -116
  68. package/dist/extensions/where-is-in.extension.js +11 -27
  69. package/dist/extensions/where-json.extension.d.ts +4 -0
  70. package/dist/extensions/where-json.extension.js +1 -9
  71. package/dist/extensions/where-relation-exists.extension.d.ts +6 -6
  72. package/dist/extensions/where-relation-exists.extension.js +5 -25
  73. package/dist/helpers.d.ts +5 -0
  74. package/dist/helpers.js +12 -3
  75. package/dist/index.d.ts +1 -2
  76. package/dist/index.js +1 -4
  77. package/dist/types/extensions/cursor-pagination.types.d.ts +5 -0
  78. package/dist/types/extensions/get-many-with-totals.types.d.ts +4 -0
  79. package/dist/types/extensions/index.d.ts +1 -0
  80. package/dist/types/extensions/index.js +1 -0
  81. package/dist/types/extensions/typed-group-by.types.d.ts +2 -2
  82. package/dist/types/extensions/typed-join-and-map.types.d.ts +6 -0
  83. package/dist/types/extensions/typed-join-and-map.types.js +2 -0
  84. package/dist/types/modules/typed-root.types.d.ts +13 -7
  85. package/dist/utils/calculated-column.utils.d.ts +11 -0
  86. package/dist/utils/calculated-column.utils.js +33 -4
  87. package/dist/utils/common.utils.d.ts +2 -0
  88. package/dist/utils/common.utils.js +4 -1
  89. package/dist/utils/cursor.utils.js +4 -6
  90. package/dist/utils/json-path.utils.js +2 -2
  91. package/dist/utils/pagination.utils.d.ts +7 -0
  92. package/dist/utils/pagination.utils.js +20 -10
  93. package/dist/utils/parameter.utils.d.ts +10 -0
  94. package/dist/utils/parameter.utils.js +22 -1
  95. package/dist/utils/period.utils.js +2 -1
  96. package/dist/utils/prototype.utils.d.ts +9 -0
  97. package/dist/utils/prototype.utils.js +12 -2
  98. package/dist/utils/query-builder.utils.d.ts +43 -4
  99. package/dist/utils/query-builder.utils.js +239 -36
  100. package/dist/utils/reserved-qualifier-guard.utils.d.ts +36 -0
  101. package/dist/utils/reserved-qualifier-guard.utils.js +98 -0
  102. package/dist/utils/reserved-qualifier.utils.d.ts +33 -0
  103. package/dist/utils/reserved-qualifier.utils.js +252 -0
  104. package/dist/utils/table.utils.d.ts +27 -11
  105. package/dist/utils/table.utils.js +58 -23
  106. package/dist/utils/time-zone.utils.d.ts +8 -0
  107. package/dist/utils/time-zone.utils.js +15 -5
  108. package/dist/utils/typed-where.utils.d.ts +9 -0
  109. package/dist/utils/typed-where.utils.js +17 -0
  110. package/dist/utils/where.utils.d.ts +2 -0
  111. package/dist/utils/where.utils.js +21 -14
  112. 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 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
  }
@@ -1,39 +1,23 @@
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 where_utils_1 = require("../utils/where.utils");
5
+ /* eslint-enable @typescript-eslint/no-empty-interface, @typescript-eslint/no-unused-vars */
6
6
  // patching
7
+ const createWhereIsInMethod = (method, operator) => function (field, array) {
8
+ return attachWhereIsIn(this, method, field, operator, array);
9
+ };
7
10
  const extension = {
8
11
  prototype: {
9
- whereIsIn: function (field, array) {
10
- return attachWhereIsIn(this, 'where', field, 'IN', array);
11
- },
12
- andWhereIsIn: function (field, array) {
13
- return attachWhereIsIn(this, 'andWhere', field, 'IN', array);
14
- },
15
- orWhereIsIn: function (field, array) {
16
- return attachWhereIsIn(this, 'orWhere', field, 'IN', array);
17
- },
18
- whereIsNotIn: function (field, array) {
19
- return attachWhereIsIn(this, 'where', field, 'NOT IN', array);
20
- },
21
- andWhereIsNotIn: function (field, array) {
22
- return attachWhereIsIn(this, 'andWhere', field, 'NOT IN', array);
23
- },
24
- orWhereIsNotIn: function (field, array) {
25
- return attachWhereIsIn(this, 'orWhere', field, 'NOT IN', array);
26
- },
12
+ whereIsIn: createWhereIsInMethod('where', 'IN'),
13
+ andWhereIsIn: createWhereIsInMethod('andWhere', 'IN'),
14
+ orWhereIsIn: createWhereIsInMethod('orWhere', 'IN'),
15
+ whereIsNotIn: createWhereIsInMethod('where', 'NOT IN'),
16
+ andWhereIsNotIn: createWhereIsInMethod('andWhere', 'NOT IN'),
17
+ orWhereIsNotIn: createWhereIsInMethod('orWhere', 'NOT IN'),
27
18
  },
28
19
  };
29
- const queryBuilders = [
30
- typeorm_1.SelectQueryBuilder,
31
- typeorm_1.UpdateQueryBuilder,
32
- typeorm_1.DeleteQueryBuilder,
33
- ];
34
- queryBuilders.forEach((builder) => {
35
- (0, prototype_utils_1.patchPrototype)(builder, extension);
36
- });
20
+ (0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, extension);
37
21
  // implementation
38
22
  function attachWhereIsIn(builder, method, field, operator, array) {
39
23
  if (method && typeof field === 'string' && typeof operator === 'string') {
@@ -53,3 +53,7 @@ declare module 'typeorm/query-builder/DeleteQueryBuilder' {
53
53
  interface DeleteQueryBuilder<Entity extends ObjectLiteral> extends WhereJsonMethods {
54
54
  }
55
55
  }
56
+ declare module 'typeorm/query-builder/SoftDeleteQueryBuilder' {
57
+ interface SoftDeleteQueryBuilder<Entity extends ObjectLiteral> extends WhereJsonMethods {
58
+ }
59
+ }
@@ -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");
@@ -22,14 +21,7 @@ const extension = {
22
21
  orWhereJsonHasKey: createWhereJsonHasKeyMethod('orWhere'),
23
22
  },
24
23
  };
25
- const queryBuilders = [
26
- typeorm_1.SelectQueryBuilder,
27
- typeorm_1.UpdateQueryBuilder,
28
- typeorm_1.DeleteQueryBuilder,
29
- ];
30
- queryBuilders.forEach((builder) => {
31
- (0, prototype_utils_1.patchPrototype)(builder, extension);
32
- });
24
+ (0, prototype_utils_1.patchPrototypes)(prototype_utils_1.WHERE_QUERY_BUILDERS, extension);
33
25
  // implementation
34
26
  /**
35
27
  * `CAST("table"."column" AS jsonb)`: makes `json` and `simple-json` (text) columns work, and is dropped by PostgreSQL
@@ -19,17 +19,17 @@ type RelatedCondition<Related extends ObjectLiteral> = (subQuery: SelectQueryBui
19
19
  */
20
20
  export interface WhereRelationExistsMethods<Entity extends ObjectLiteral> {
21
21
  /** Sets `WHERE EXISTS (…)` over the relation, replacing the WHERE conditions set before. */
22
- whereRelationExists<Related extends ObjectLiteral, Type extends ObjectLiteral = TypedRoot<Entity>>(relation: RelationSelection<Type, Related>, alias: string, where?: RelatedCondition<Related>): this;
22
+ whereRelationExists<Related extends ObjectLiteral, Type extends ObjectLiteral = TypedRoot<Entity, this>>(relation: RelationSelection<Type, Related>, alias: string, where?: RelatedCondition<Related>): this;
23
23
  /** Adds `AND EXISTS (…)` over the relation. */
24
- andWhereRelationExists<Related extends ObjectLiteral, Type extends ObjectLiteral = TypedRoot<Entity>>(relation: RelationSelection<Type, Related>, alias: string, where?: RelatedCondition<Related>): this;
24
+ andWhereRelationExists<Related extends ObjectLiteral, Type extends ObjectLiteral = TypedRoot<Entity, this>>(relation: RelationSelection<Type, Related>, alias: string, where?: RelatedCondition<Related>): this;
25
25
  /** Adds `OR EXISTS (…)` over the relation. */
26
- orWhereRelationExists<Related extends ObjectLiteral, Type extends ObjectLiteral = TypedRoot<Entity>>(relation: RelationSelection<Type, Related>, alias: string, where?: RelatedCondition<Related>): this;
26
+ orWhereRelationExists<Related extends ObjectLiteral, Type extends ObjectLiteral = TypedRoot<Entity, this>>(relation: RelationSelection<Type, Related>, alias: string, where?: RelatedCondition<Related>): this;
27
27
  /** Sets `WHERE NOT EXISTS (…)` over the relation, replacing the WHERE conditions set before. */
28
- whereRelationNotExists<Related extends ObjectLiteral, Type extends ObjectLiteral = TypedRoot<Entity>>(relation: RelationSelection<Type, Related>, alias: string, where?: RelatedCondition<Related>): this;
28
+ whereRelationNotExists<Related extends ObjectLiteral, Type extends ObjectLiteral = TypedRoot<Entity, this>>(relation: RelationSelection<Type, Related>, alias: string, where?: RelatedCondition<Related>): this;
29
29
  /** Adds `AND NOT EXISTS (…)` over the relation. */
30
- andWhereRelationNotExists<Related extends ObjectLiteral, Type extends ObjectLiteral = TypedRoot<Entity>>(relation: RelationSelection<Type, Related>, alias: string, where?: RelatedCondition<Related>): this;
30
+ andWhereRelationNotExists<Related extends ObjectLiteral, Type extends ObjectLiteral = TypedRoot<Entity, this>>(relation: RelationSelection<Type, Related>, alias: string, where?: RelatedCondition<Related>): this;
31
31
  /** Adds `OR NOT EXISTS (…)` over the relation. */
32
- orWhereRelationNotExists<Related extends ObjectLiteral, Type extends ObjectLiteral = TypedRoot<Entity>>(relation: RelationSelection<Type, Related>, alias: string, where?: RelatedCondition<Related>): this;
32
+ orWhereRelationNotExists<Related extends ObjectLiteral, Type extends ObjectLiteral = TypedRoot<Entity, this>>(relation: RelationSelection<Type, Related>, alias: string, where?: RelatedCondition<Related>): this;
33
33
  }
34
34
  declare module 'typeorm/query-builder/SelectQueryBuilder' {
35
35
  interface SelectQueryBuilder<Entity extends ObjectLiteral> extends WhereRelationExistsMethods<Entity> {