typeorm-extensions 2.1.0 → 2.2.0-rc.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/LICENSE +21 -0
- package/README.md +6 -3
- package/dist/decorators/calculated-column.decorator.d.ts +30 -0
- package/dist/decorators/calculated-column.decorator.js +82 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +17 -0
- package/dist/extensions/calculated-column.extension.d.ts +33 -0
- package/dist/extensions/calculated-column.extension.js +33 -0
- package/dist/extensions/cursor-pagination.extension.d.ts +2 -1
- package/dist/extensions/cursor-pagination.extension.js +4 -3
- package/dist/extensions/get-many-with-totals.extension.d.ts +9 -1
- package/dist/extensions/get-many-with-totals.extension.js +158 -10
- package/dist/extensions/index.d.ts +7 -0
- package/dist/extensions/index.js +7 -0
- package/dist/extensions/join-lateral.extension.d.ts +19 -0
- package/dist/extensions/join-lateral.extension.js +50 -0
- package/dist/extensions/join-unnest.extension.d.ts +19 -0
- package/dist/extensions/join-unnest.extension.js +40 -0
- package/dist/extensions/order.extension.js +18 -7
- package/dist/extensions/query-returning.extension.d.ts +29 -0
- package/dist/extensions/query-returning.extension.js +50 -0
- package/dist/extensions/typed/index.d.ts +3 -0
- package/dist/extensions/typed/index.js +3 -2
- package/dist/extensions/typed/typed-distinct/typed-distinct.extension.d.ts +3 -2
- package/dist/extensions/typed/typed-group-by/typed-group-by.extension.d.ts +24 -0
- package/dist/extensions/typed/typed-group-by/typed-group-by.extension.js +31 -0
- package/dist/extensions/typed/typed-having/typed-having.extension.d.ts +36 -0
- package/dist/extensions/typed/typed-having/typed-having.extension.js +42 -0
- package/dist/extensions/typed/typed-joins/typed-joins.extension.d.ts +5 -4
- package/dist/extensions/typed/typed-order-by/typed-order-by-array-position.extension.d.ts +3 -2
- package/dist/extensions/typed/typed-order-by/typed-order-by-array-position.extension.js +10 -2
- package/dist/extensions/typed/typed-order-by/typed-order-by.extension.d.ts +3 -2
- package/dist/extensions/typed/typed-order-by/typed-order-by.extension.js +3 -2
- package/dist/extensions/typed/typed-root.extension.d.ts +25 -0
- package/dist/extensions/typed/typed-root.extension.js +13 -0
- package/dist/extensions/typed/typed-select/typed-select.extension.d.ts +5 -4
- package/dist/extensions/typed/typed-select/typed-select.extension.js +3 -2
- package/dist/extensions/typed/typed-where/typed-period-filter.extension.d.ts +2 -1
- package/dist/extensions/typed/typed-where/typed-where-array.extension.d.ts +10 -9
- package/dist/extensions/typed/typed-where/typed-where-array.extension.js +32 -0
- package/dist/extensions/typed/typed-where/typed-where-ilike.extension.d.ts +7 -6
- package/dist/extensions/typed/typed-where/typed-where-is-any.extension.d.ts +7 -6
- package/dist/extensions/typed/typed-where/typed-where-is-distinct-from.extension.d.ts +7 -6
- package/dist/extensions/typed/typed-where/typed-where-is-in.extension.d.ts +7 -6
- package/dist/extensions/typed/typed-where/typed-where-json.extension.d.ts +7 -6
- package/dist/extensions/typed/typed-where/typed-where-lower.extension.d.ts +7 -6
- package/dist/extensions/typed/typed-where/typed-where-similar.extension.d.ts +5 -4
- package/dist/extensions/typed/typed-where/typed-where.extension.d.ts +4 -3
- package/dist/extensions/union.extension.d.ts +22 -0
- package/dist/extensions/union.extension.js +52 -0
- package/dist/extensions/where-exists.extension.d.ts +50 -0
- package/dist/extensions/where-exists.extension.js +64 -0
- package/dist/extensions/where-relation-exists.extension.d.ts +38 -0
- package/dist/extensions/where-relation-exists.extension.js +95 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/types/extensions/cursor-pagination.types.d.ts +5 -0
- package/dist/types/extensions/get-many-with-totals.types.d.ts +19 -0
- package/dist/types/extensions/index.d.ts +5 -0
- package/dist/types/extensions/index.js +5 -0
- package/dist/types/extensions/join-lateral.types.d.ts +6 -0
- package/dist/types/extensions/join-lateral.types.js +2 -0
- package/dist/types/extensions/period.types.d.ts +8 -0
- package/dist/types/extensions/query-returning.types.d.ts +11 -0
- package/dist/types/extensions/query-returning.types.js +2 -0
- package/dist/types/extensions/typed-group-by.types.d.ts +8 -0
- package/dist/types/extensions/typed-group-by.types.js +2 -0
- package/dist/types/extensions/typed-having.types.d.ts +2 -0
- package/dist/types/extensions/typed-having.types.js +2 -0
- package/dist/types/extensions/union.types.d.ts +12 -0
- package/dist/types/extensions/union.types.js +2 -0
- package/dist/types/extensions/where.types.d.ts +1 -0
- package/dist/types/modules/typed-root.types.d.ts +13 -0
- package/dist/types/modules/typed-root.types.js +2 -0
- package/dist/utils/calculated-column.utils.d.ts +21 -0
- package/dist/utils/calculated-column.utils.js +63 -0
- package/dist/utils/parameter.utils.d.ts +7 -0
- package/dist/utils/parameter.utils.js +21 -0
- package/dist/utils/period.utils.js +7 -2
- package/dist/utils/prototype.utils.d.ts +5 -1
- package/dist/utils/prototype.utils.js +4 -1
- package/dist/utils/proxy-key.utils.d.ts +3 -3
- package/dist/utils/proxy-key.utils.js +7 -7
- package/dist/utils/query-builder.utils.d.ts +8 -0
- package/dist/utils/query-builder.utils.js +30 -2
- package/dist/utils/table.utils.d.ts +112 -2
- package/dist/utils/table.utils.js +206 -11
- package/dist/utils/time-zone.utils.d.ts +8 -0
- package/dist/utils/time-zone.utils.js +102 -0
- package/dist/utils/where.utils.d.ts +2 -2
- package/dist/utils/where.utils.js +23 -2
- package/package.json +2 -2
|
@@ -2,6 +2,7 @@ import '../../where-array.extension';
|
|
|
2
2
|
import { ObjectLiteral } from 'typeorm';
|
|
3
3
|
import { DeepUnwrapArray, ProxyColumnValueType } from '../../../types/modules/proxy-callback.types';
|
|
4
4
|
import { ArgsType } from '../../../types/util-types';
|
|
5
|
+
import type { TypedRoot } from '../../../types/modules/typed-root.types';
|
|
5
6
|
/**
|
|
6
7
|
* Typesafe conditions on PostgreSQL array columns: the column comes from an entity property.
|
|
7
8
|
* See {@link WhereArrayMethods}.
|
|
@@ -12,43 +13,43 @@ export interface TypedWhereArrayMethods<Entity extends ObjectLiteral> {
|
|
|
12
13
|
* If you had previously WHERE expression defined,
|
|
13
14
|
* calling this function will override previously set WHERE conditions.
|
|
14
15
|
*/
|
|
15
|
-
whereArrayContainsTyped<Type extends ObjectLiteral = Entity
|
|
16
|
+
whereArrayContainsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
16
17
|
/**
|
|
17
18
|
* Adds new AND WHERE `column @> :values` condition (PostgreSQL): the array column contains every value.
|
|
18
19
|
*/
|
|
19
|
-
andWhereArrayContainsTyped<Type extends ObjectLiteral = Entity
|
|
20
|
+
andWhereArrayContainsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
20
21
|
/**
|
|
21
22
|
* Adds new OR WHERE `column @> :values` condition (PostgreSQL): the array column contains every value.
|
|
22
23
|
*/
|
|
23
|
-
orWhereArrayContainsTyped<Type extends ObjectLiteral = Entity
|
|
24
|
+
orWhereArrayContainsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
24
25
|
/**
|
|
25
26
|
* Sets WHERE `column <@ :values` condition (PostgreSQL): every element of the array column is one of the values.
|
|
26
27
|
* If you had previously WHERE expression defined,
|
|
27
28
|
* calling this function will override previously set WHERE conditions.
|
|
28
29
|
*/
|
|
29
|
-
whereArrayContainedByTyped<Type extends ObjectLiteral = Entity
|
|
30
|
+
whereArrayContainedByTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
30
31
|
/**
|
|
31
32
|
* Adds new AND WHERE `column <@ :values` condition (PostgreSQL): every element of the array column is one of the values.
|
|
32
33
|
*/
|
|
33
|
-
andWhereArrayContainedByTyped<Type extends ObjectLiteral = Entity
|
|
34
|
+
andWhereArrayContainedByTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
34
35
|
/**
|
|
35
36
|
* Adds new OR WHERE `column <@ :values` condition (PostgreSQL): every element of the array column is one of the values.
|
|
36
37
|
*/
|
|
37
|
-
orWhereArrayContainedByTyped<Type extends ObjectLiteral = Entity
|
|
38
|
+
orWhereArrayContainedByTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
38
39
|
/**
|
|
39
40
|
* Sets WHERE `column && :values` condition (PostgreSQL): the array column has at least one of the values.
|
|
40
41
|
* If you had previously WHERE expression defined,
|
|
41
42
|
* calling this function will override previously set WHERE conditions.
|
|
42
43
|
*/
|
|
43
|
-
whereArrayOverlapsTyped<Type extends ObjectLiteral = Entity
|
|
44
|
+
whereArrayOverlapsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
44
45
|
/**
|
|
45
46
|
* Adds new AND WHERE `column && :values` condition (PostgreSQL): the array column has at least one of the values.
|
|
46
47
|
*/
|
|
47
|
-
andWhereArrayOverlapsTyped<Type extends ObjectLiteral = Entity
|
|
48
|
+
andWhereArrayOverlapsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
48
49
|
/**
|
|
49
50
|
* Adds new OR WHERE `column && :values` condition (PostgreSQL): the array column has at least one of the values.
|
|
50
51
|
*/
|
|
51
|
-
orWhereArrayOverlapsTyped<Type extends ObjectLiteral = Entity
|
|
52
|
+
orWhereArrayOverlapsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
52
53
|
}
|
|
53
54
|
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
54
55
|
interface WhereExpressionBuilder extends TypedWhereArrayMethods<ObjectLiteral> {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
require("../../where-array.extension");
|
|
4
4
|
const typeorm_1 = require("typeorm");
|
|
5
5
|
const query_builder_utils_1 = require("../../../utils/query-builder.utils");
|
|
6
|
+
const sql_utils_1 = require("../../../utils/sql.utils");
|
|
6
7
|
const prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
7
8
|
/* eslint-enable @typescript-eslint/no-empty-interface */
|
|
8
9
|
// patching
|
|
@@ -36,6 +37,37 @@ function attachWhereArrayTyped(builder, method, where, values, arrayType) {
|
|
|
36
37
|
return builder;
|
|
37
38
|
}
|
|
38
39
|
const key = (0, query_builder_utils_1.getTypedSingleColumnKey)(builder, where, `${method}Typed`);
|
|
40
|
+
if ((0, query_builder_utils_1.isTypedJsonPath)(builder, where)) {
|
|
41
|
+
return attachWhereJsonArray(builder, method, where, values, arrayType);
|
|
42
|
+
}
|
|
39
43
|
// .andWhereArrayContains(`"table"."column"`, ['value'])
|
|
40
44
|
return builder[method](key, values, arrayType);
|
|
41
45
|
}
|
|
46
|
+
const JSON_ARRAY_METHOD = /^(where|andWhere|orWhere)Array(Contains|ContainedBy|Overlaps)$/;
|
|
47
|
+
const JSON_ARRAY_OPERATORS = { Contains: '@>', ContainedBy: '<@', Overlaps: '?|' };
|
|
48
|
+
/**
|
|
49
|
+
* The array conditions on an array inside a JSON column, with jsonb operators: `@>` and `<@` against the
|
|
50
|
+
* values as a JSON array, and `?|` (any of the strings is an element) for the overlap. Empty arrays keep
|
|
51
|
+
* PostgreSQL's semantics, as for array columns.
|
|
52
|
+
*/
|
|
53
|
+
function attachWhereJsonArray(builder, method, where, values, arrayType) {
|
|
54
|
+
const methodName = `${method}Typed`;
|
|
55
|
+
const [, whereMethod, condition] = JSON_ARRAY_METHOD.exec(method);
|
|
56
|
+
if (!Array.isArray(values)) {
|
|
57
|
+
throw new TypeError(`${methodName} expects an array of values, got ${values}`);
|
|
58
|
+
}
|
|
59
|
+
if (arrayType !== undefined) {
|
|
60
|
+
throw new TypeError(`${methodName}: arrayType is for array columns, not for an array inside a JSON column`);
|
|
61
|
+
}
|
|
62
|
+
const jsonArray = `CAST(${(0, query_builder_utils_1.getTypedSingleColumnKey)(builder, where, methodName, { accessor: 'json' })} AS jsonb)`;
|
|
63
|
+
const paramName = (0, sql_utils_1.createUniqueParameterName)(whereMethod);
|
|
64
|
+
// a string or an object at the path isn't an array, but <@ and ?| would match it
|
|
65
|
+
const onArray = (condition) => `(jsonb_typeof(${jsonArray}) = 'array' AND ${condition})`;
|
|
66
|
+
if (condition === 'Overlaps') {
|
|
67
|
+
if (!values.every((value) => typeof value === 'string')) {
|
|
68
|
+
throw new TypeError(`${methodName} on an array inside a JSON column takes strings: the ?| operator matches string elements`);
|
|
69
|
+
}
|
|
70
|
+
return builder[whereMethod](onArray(`${jsonArray} ?| CAST(:${paramName} AS text[])`), { [paramName]: values });
|
|
71
|
+
}
|
|
72
|
+
return builder[whereMethod](onArray(`${jsonArray} ${JSON_ARRAY_OPERATORS[condition]} CAST(:${paramName} AS jsonb)`), { [paramName]: JSON.stringify(values) });
|
|
73
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ObjectLiteral } from 'typeorm';
|
|
2
2
|
import { DeepUnwrapArray, ProxyColumnValueType } from '../../../types/modules/proxy-callback.types';
|
|
3
3
|
import type { SearchSelector, TypedILikeOptions, TypedSearchOptions } from '../../../types/extensions/search.types';
|
|
4
|
+
import type { TypedRoot } from '../../../types/modules/typed-root.types';
|
|
4
5
|
/**
|
|
5
6
|
* Case-insensitive search methods: `ILIKE` on PostgreSQL, `LIKE` on MySQL / MariaDB and SQLite.
|
|
6
7
|
* `%`, `_` and `\` in the value are escaped, and a blank value adds no condition.
|
|
@@ -13,17 +14,17 @@ export interface TypedWhereILikeMethods<Entity extends ObjectLiteral> {
|
|
|
13
14
|
* If you had previously WHERE expression defined,
|
|
14
15
|
* calling this function will override previously set WHERE conditions.
|
|
15
16
|
*/
|
|
16
|
-
whereILikeTyped<Type extends ObjectLiteral = Entity
|
|
17
|
+
whereILikeTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: string | null | undefined, options?: TypedILikeOptions): this;
|
|
17
18
|
/**
|
|
18
19
|
* Adds new AND WHERE `column ILIKE :pattern` condition in the query builder.
|
|
19
20
|
* `null`, `undefined` or a blank value adds no condition.
|
|
20
21
|
*/
|
|
21
|
-
andWhereILikeTyped<Type extends ObjectLiteral = Entity
|
|
22
|
+
andWhereILikeTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: string | null | undefined, options?: TypedILikeOptions): this;
|
|
22
23
|
/**
|
|
23
24
|
* Adds new OR WHERE `column ILIKE :pattern` condition in the query builder.
|
|
24
25
|
* `null`, `undefined` or a blank value adds no condition.
|
|
25
26
|
*/
|
|
26
|
-
orWhereILikeTyped<Type extends ObjectLiteral = Entity
|
|
27
|
+
orWhereILikeTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: string | null | undefined, options?: TypedILikeOptions): this;
|
|
27
28
|
/**
|
|
28
29
|
* Sets WHERE `(col1 ILIKE :pattern OR col2 ILIKE :pattern …)` condition in the query builder:
|
|
29
30
|
* one group, one parameter for every column. A selector is a typed callback (it may select
|
|
@@ -32,17 +33,17 @@ export interface TypedWhereILikeMethods<Entity extends ObjectLiteral> {
|
|
|
32
33
|
* If you had previously WHERE expression defined,
|
|
33
34
|
* calling this function will override previously set WHERE conditions.
|
|
34
35
|
*/
|
|
35
|
-
whereSearchTyped<Type extends ObjectLiteral = Entity
|
|
36
|
+
whereSearchTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(selectors: ReadonlyArray<SearchSelector<Type>>, value: string | null | undefined, options?: TypedSearchOptions): this;
|
|
36
37
|
/**
|
|
37
38
|
* Adds new AND WHERE `(col1 ILIKE :pattern OR col2 ILIKE :pattern …)` condition in the query builder.
|
|
38
39
|
* A value shorter than `options.minLength` (default 1, after trimming) adds no condition.
|
|
39
40
|
*/
|
|
40
|
-
andWhereSearchTyped<Type extends ObjectLiteral = Entity
|
|
41
|
+
andWhereSearchTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(selectors: ReadonlyArray<SearchSelector<Type>>, value: string | null | undefined, options?: TypedSearchOptions): this;
|
|
41
42
|
/**
|
|
42
43
|
* Adds new OR WHERE `(col1 ILIKE :pattern OR col2 ILIKE :pattern …)` condition in the query builder.
|
|
43
44
|
* A value shorter than `options.minLength` (default 1, after trimming) adds no condition.
|
|
44
45
|
*/
|
|
45
|
-
orWhereSearchTyped<Type extends ObjectLiteral = Entity
|
|
46
|
+
orWhereSearchTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(selectors: ReadonlyArray<SearchSelector<Type>>, value: string | null | undefined, options?: TypedSearchOptions): this;
|
|
46
47
|
}
|
|
47
48
|
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
48
49
|
interface WhereExpressionBuilder extends TypedWhereILikeMethods<ObjectLiteral> {
|
|
@@ -2,6 +2,7 @@ import '../../where-is-any.extension';
|
|
|
2
2
|
import { ObjectLiteral } from 'typeorm';
|
|
3
3
|
import { DeepUnwrapArray, ProxyColumnValueType } from '../../../types/modules/proxy-callback.types';
|
|
4
4
|
import { TypedArrayArg, TypeOrDefault, UnsetType } from '../../../types/modules/typed-params.types';
|
|
5
|
+
import type { TypedRoot } from '../../../types/modules/typed-root.types';
|
|
5
6
|
export interface TypedWhereIsAnyMethods<Entity extends ObjectLiteral> {
|
|
6
7
|
/**
|
|
7
8
|
* Sets WHERE `column = ANY(:array)` condition in the query builder (PostgreSQL).
|
|
@@ -10,30 +11,30 @@ export interface TypedWhereIsAnyMethods<Entity extends ObjectLiteral> {
|
|
|
10
11
|
* If you had previously WHERE expression defined,
|
|
11
12
|
* calling this function will override previously set WHERE conditions.
|
|
12
13
|
*/
|
|
13
|
-
whereIsAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity
|
|
14
|
+
whereIsAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity>>>) => Value, array?: TypedArrayArg<Type, Value>, arrayType?: string): this;
|
|
14
15
|
/**
|
|
15
16
|
* Adds new AND WHERE `column = ANY(:array)` condition in the query builder (PostgreSQL).
|
|
16
17
|
*/
|
|
17
|
-
andWhereIsAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity
|
|
18
|
+
andWhereIsAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity>>>) => Value, array?: TypedArrayArg<Type, Value>, arrayType?: string): this;
|
|
18
19
|
/**
|
|
19
20
|
* Adds new OR WHERE `column = ANY(:array)` condition in the query builder (PostgreSQL).
|
|
20
21
|
*/
|
|
21
|
-
orWhereIsAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity
|
|
22
|
+
orWhereIsAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity>>>) => Value, array?: TypedArrayArg<Type, Value>, arrayType?: string): this;
|
|
22
23
|
/**
|
|
23
24
|
* Sets WHERE `column <> ALL(:array)` condition in the query builder (PostgreSQL):
|
|
24
25
|
* the column differs from every value of the array.
|
|
25
26
|
* If you had previously WHERE expression defined,
|
|
26
27
|
* calling this function will override previously set WHERE conditions.
|
|
27
28
|
*/
|
|
28
|
-
whereIsNotAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity
|
|
29
|
+
whereIsNotAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity>>>) => Value, array?: TypedArrayArg<Type, Value>, arrayType?: string): this;
|
|
29
30
|
/**
|
|
30
31
|
* Adds new AND WHERE `column <> ALL(:array)` condition in the query builder (PostgreSQL).
|
|
31
32
|
*/
|
|
32
|
-
andWhereIsNotAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity
|
|
33
|
+
andWhereIsNotAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity>>>) => Value, array?: TypedArrayArg<Type, Value>, arrayType?: string): this;
|
|
33
34
|
/**
|
|
34
35
|
* Adds new OR WHERE `column <> ALL(:array)` condition in the query builder (PostgreSQL).
|
|
35
36
|
*/
|
|
36
|
-
orWhereIsNotAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity
|
|
37
|
+
orWhereIsNotAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity>>>) => Value, array?: TypedArrayArg<Type, Value>, arrayType?: string): this;
|
|
37
38
|
}
|
|
38
39
|
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
39
40
|
interface WhereExpressionBuilder extends TypedWhereIsAnyMethods<ObjectLiteral> {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import '../../where-is-distinct-from.extension';
|
|
2
2
|
import { ObjectLiteral } from 'typeorm';
|
|
3
3
|
import { DeepUnwrapArray, ProxyColumnValueType } from '../../../types/modules/proxy-callback.types';
|
|
4
|
+
import type { TypedRoot } from '../../../types/modules/typed-root.types';
|
|
4
5
|
/**
|
|
5
6
|
* Typesafe null-safe comparisons: the column comes from an entity property.
|
|
6
7
|
* See {@link WhereDistinctMethods}.
|
|
@@ -11,29 +12,29 @@ export interface TypedWhereDistinctMethods<Entity extends ObjectLiteral> {
|
|
|
11
12
|
* If you had previously WHERE expression defined,
|
|
12
13
|
* calling this function will override previously set WHERE conditions.
|
|
13
14
|
*/
|
|
14
|
-
whereIsDistinctFromTyped<Type extends ObjectLiteral = Entity
|
|
15
|
+
whereIsDistinctFromTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: unknown): this;
|
|
15
16
|
/**
|
|
16
17
|
* Adds new AND WHERE `column IS DISTINCT FROM :value` condition: the column differs from the value, `NULL` included.
|
|
17
18
|
*/
|
|
18
|
-
andWhereIsDistinctFromTyped<Type extends ObjectLiteral = Entity
|
|
19
|
+
andWhereIsDistinctFromTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: unknown): this;
|
|
19
20
|
/**
|
|
20
21
|
* Adds new OR WHERE `column IS DISTINCT FROM :value` condition: the column differs from the value, `NULL` included.
|
|
21
22
|
*/
|
|
22
|
-
orWhereIsDistinctFromTyped<Type extends ObjectLiteral = Entity
|
|
23
|
+
orWhereIsDistinctFromTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: unknown): this;
|
|
23
24
|
/**
|
|
24
25
|
* Sets WHERE `column IS NOT DISTINCT FROM :value` condition: the column equals the value, `NULL` included.
|
|
25
26
|
* If you had previously WHERE expression defined,
|
|
26
27
|
* calling this function will override previously set WHERE conditions.
|
|
27
28
|
*/
|
|
28
|
-
whereIsNotDistinctFromTyped<Type extends ObjectLiteral = Entity
|
|
29
|
+
whereIsNotDistinctFromTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: unknown): this;
|
|
29
30
|
/**
|
|
30
31
|
* Adds new AND WHERE `column IS NOT DISTINCT FROM :value` condition: the column equals the value, `NULL` included.
|
|
31
32
|
*/
|
|
32
|
-
andWhereIsNotDistinctFromTyped<Type extends ObjectLiteral = Entity
|
|
33
|
+
andWhereIsNotDistinctFromTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: unknown): this;
|
|
33
34
|
/**
|
|
34
35
|
* Adds new OR WHERE `column IS NOT DISTINCT FROM :value` condition: the column equals the value, `NULL` included.
|
|
35
36
|
*/
|
|
36
|
-
orWhereIsNotDistinctFromTyped<Type extends ObjectLiteral = Entity
|
|
37
|
+
orWhereIsNotDistinctFromTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: unknown): this;
|
|
37
38
|
}
|
|
38
39
|
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
39
40
|
interface WhereExpressionBuilder extends TypedWhereDistinctMethods<ObjectLiteral> {
|
|
@@ -2,35 +2,36 @@ import '../../where-is-in.extension';
|
|
|
2
2
|
import { ObjectLiteral } from 'typeorm';
|
|
3
3
|
import { DeepUnwrapArray, ProxyColumnValueType } from '../../../types/modules/proxy-callback.types';
|
|
4
4
|
import { TypedArrayArg, TypeOrDefault, UnsetType } from '../../../types/modules/typed-params.types';
|
|
5
|
+
import type { TypedRoot } from '../../../types/modules/typed-root.types';
|
|
5
6
|
export interface TypedWhereIsInMethods<Entity extends ObjectLiteral> {
|
|
6
7
|
/**
|
|
7
8
|
* Sets WHERE IN condition in the query builder.
|
|
8
9
|
* If you had previously WHERE expression defined,
|
|
9
10
|
* calling this function will override previously set WHERE conditions.
|
|
10
11
|
*/
|
|
11
|
-
whereIsInTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity
|
|
12
|
+
whereIsInTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity>>>) => Value, array?: TypedArrayArg<Type, Value>): this;
|
|
12
13
|
/**
|
|
13
14
|
* Adds new AND WHERE IN condition in the query builder.
|
|
14
15
|
*/
|
|
15
|
-
andWhereIsInTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity
|
|
16
|
+
andWhereIsInTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity>>>) => Value, array?: TypedArrayArg<Type, Value>): this;
|
|
16
17
|
/**
|
|
17
18
|
* Adds new OR WHERE IN condition in the query builder.
|
|
18
19
|
*/
|
|
19
|
-
orWhereIsInTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity
|
|
20
|
+
orWhereIsInTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity>>>) => Value, array?: TypedArrayArg<Type, Value>): this;
|
|
20
21
|
/**
|
|
21
22
|
* Sets WHERE NOT IN condition in the query builder.
|
|
22
23
|
* If you had previously WHERE expression defined,
|
|
23
24
|
* calling this function will override previously set WHERE conditions.
|
|
24
25
|
*/
|
|
25
|
-
whereIsNotInTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity
|
|
26
|
+
whereIsNotInTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity>>>) => Value, array?: TypedArrayArg<Type, Value>): this;
|
|
26
27
|
/**
|
|
27
28
|
* Adds new AND WHERE NOT IN condition in the query builder.
|
|
28
29
|
*/
|
|
29
|
-
andWhereIsNotInTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity
|
|
30
|
+
andWhereIsNotInTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity>>>) => Value, array?: TypedArrayArg<Type, Value>): this;
|
|
30
31
|
/**
|
|
31
32
|
* Adds new OR WHERE NOT IN condition in the query builder.
|
|
32
33
|
*/
|
|
33
|
-
orWhereIsNotInTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity
|
|
34
|
+
orWhereIsNotInTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, TypedRoot<Entity>>>) => Value, array?: TypedArrayArg<Type, Value>): this;
|
|
34
35
|
}
|
|
35
36
|
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
36
37
|
interface WhereExpressionBuilder extends TypedWhereIsInMethods<ObjectLiteral> {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import '../../where-json.extension';
|
|
2
2
|
import { ObjectLiteral } from 'typeorm';
|
|
3
3
|
import { DeepUnwrapArray, ProxyColumnValueType } from '../../../types/modules/proxy-callback.types';
|
|
4
|
+
import type { TypedRoot } from '../../../types/modules/typed-root.types';
|
|
4
5
|
/**
|
|
5
6
|
* Typesafe conditions on PostgreSQL `jsonb` / `json` columns: the column comes from an entity property.
|
|
6
7
|
* See {@link WhereJsonMethods}.
|
|
@@ -11,29 +12,29 @@ export interface TypedWhereJsonMethods<Entity extends ObjectLiteral> {
|
|
|
11
12
|
* If you had previously WHERE expression defined,
|
|
12
13
|
* calling this function will override previously set WHERE conditions.
|
|
13
14
|
*/
|
|
14
|
-
whereJsonContainsTyped<Type extends ObjectLiteral = Entity
|
|
15
|
+
whereJsonContainsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: unknown): this;
|
|
15
16
|
/**
|
|
16
17
|
* Adds new AND WHERE `column @> :value` condition (PostgreSQL): the JSON document contains `value`.
|
|
17
18
|
*/
|
|
18
|
-
andWhereJsonContainsTyped<Type extends ObjectLiteral = Entity
|
|
19
|
+
andWhereJsonContainsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: unknown): this;
|
|
19
20
|
/**
|
|
20
21
|
* Adds new OR WHERE `column @> :value` condition (PostgreSQL): the JSON document contains `value`.
|
|
21
22
|
*/
|
|
22
|
-
orWhereJsonContainsTyped<Type extends ObjectLiteral = Entity
|
|
23
|
+
orWhereJsonContainsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: unknown): this;
|
|
23
24
|
/**
|
|
24
25
|
* Sets WHERE `column ? :key` condition (PostgreSQL): the JSON object has the top-level key.
|
|
25
26
|
* If you had previously WHERE expression defined,
|
|
26
27
|
* calling this function will override previously set WHERE conditions.
|
|
27
28
|
*/
|
|
28
|
-
whereJsonHasKeyTyped<Type extends ObjectLiteral = Entity
|
|
29
|
+
whereJsonHasKeyTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, key: string): this;
|
|
29
30
|
/**
|
|
30
31
|
* Adds new AND WHERE `column ? :key` condition (PostgreSQL): the JSON object has the top-level key.
|
|
31
32
|
*/
|
|
32
|
-
andWhereJsonHasKeyTyped<Type extends ObjectLiteral = Entity
|
|
33
|
+
andWhereJsonHasKeyTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, key: string): this;
|
|
33
34
|
/**
|
|
34
35
|
* Adds new OR WHERE `column ? :key` condition (PostgreSQL): the JSON object has the top-level key.
|
|
35
36
|
*/
|
|
36
|
-
orWhereJsonHasKeyTyped<Type extends ObjectLiteral = Entity
|
|
37
|
+
orWhereJsonHasKeyTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, key: string): this;
|
|
37
38
|
}
|
|
38
39
|
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
39
40
|
interface WhereExpressionBuilder extends TypedWhereJsonMethods<ObjectLiteral> {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ObjectLiteral } from 'typeorm';
|
|
2
2
|
import { DeepUnwrapArray, ProxyColumnValueType } from '../../../types/modules/proxy-callback.types';
|
|
3
3
|
import type { TypedLowerOptions } from '../../../types/extensions/search.types';
|
|
4
|
+
import type { TypedRoot } from '../../../types/modules/typed-root.types';
|
|
4
5
|
/**
|
|
5
6
|
* Case-insensitive equality: `LOWER(column) = LOWER(:value)`. `options.normalize` changes the
|
|
6
7
|
* wrapping of both sides, e.g. `(sql) => \`LOWER(TRIM(${sql}))\``, to match an expression index.
|
|
@@ -12,34 +13,34 @@ export interface TypedWhereLowerMethods<Entity extends ObjectLiteral> {
|
|
|
12
13
|
* If you had previously WHERE expression defined,
|
|
13
14
|
* calling this function will override previously set WHERE conditions.
|
|
14
15
|
*/
|
|
15
|
-
whereLowerEqualsTyped<Type extends ObjectLiteral = Entity
|
|
16
|
+
whereLowerEqualsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: string | null | undefined, options?: TypedLowerOptions): this;
|
|
16
17
|
/**
|
|
17
18
|
* Adds new AND WHERE `LOWER(column) = LOWER(:value)` condition in the query builder.
|
|
18
19
|
* `null` / `undefined` matches nothing (`FALSE`).
|
|
19
20
|
*/
|
|
20
|
-
andWhereLowerEqualsTyped<Type extends ObjectLiteral = Entity
|
|
21
|
+
andWhereLowerEqualsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: string | null | undefined, options?: TypedLowerOptions): this;
|
|
21
22
|
/**
|
|
22
23
|
* Adds new OR WHERE `LOWER(column) = LOWER(:value)` condition in the query builder.
|
|
23
24
|
* `null` / `undefined` matches nothing (`FALSE`).
|
|
24
25
|
*/
|
|
25
|
-
orWhereLowerEqualsTyped<Type extends ObjectLiteral = Entity
|
|
26
|
+
orWhereLowerEqualsTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: string | null | undefined, options?: TypedLowerOptions): this;
|
|
26
27
|
/**
|
|
27
28
|
* Sets WHERE `LOWER(column) IN (LOWER(:v1), LOWER(:v2), …)` condition in the query builder.
|
|
28
29
|
* An empty or missing array matches nothing (`FALSE`), like `whereIsIn`.
|
|
29
30
|
* If you had previously WHERE expression defined,
|
|
30
31
|
* calling this function will override previously set WHERE conditions.
|
|
31
32
|
*/
|
|
32
|
-
whereIsInLowerTyped<Type extends ObjectLiteral = Entity
|
|
33
|
+
whereIsInLowerTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ReadonlyArray<string> | null | undefined, options?: TypedLowerOptions): this;
|
|
33
34
|
/**
|
|
34
35
|
* Adds new AND WHERE `LOWER(column) IN (LOWER(:v1), LOWER(:v2), …)` condition in the query builder.
|
|
35
36
|
* An empty or missing array matches nothing (`FALSE`).
|
|
36
37
|
*/
|
|
37
|
-
andWhereIsInLowerTyped<Type extends ObjectLiteral = Entity
|
|
38
|
+
andWhereIsInLowerTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ReadonlyArray<string> | null | undefined, options?: TypedLowerOptions): this;
|
|
38
39
|
/**
|
|
39
40
|
* Adds new OR WHERE `LOWER(column) IN (LOWER(:v1), LOWER(:v2), …)` condition in the query builder.
|
|
40
41
|
* An empty or missing array matches nothing (`FALSE`).
|
|
41
42
|
*/
|
|
42
|
-
orWhereIsInLowerTyped<Type extends ObjectLiteral = Entity
|
|
43
|
+
orWhereIsInLowerTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ReadonlyArray<string> | null | undefined, options?: TypedLowerOptions): this;
|
|
43
44
|
}
|
|
44
45
|
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
45
46
|
interface WhereExpressionBuilder extends TypedWhereLowerMethods<ObjectLiteral> {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ObjectLiteral } from 'typeorm';
|
|
2
2
|
import { DeepUnwrapArray, ProxyColumnValueType } from '../../../types/modules/proxy-callback.types';
|
|
3
3
|
import type { SimilarityScoreOptions, TypedSimilarOptions } from '../../../types/extensions/search.types';
|
|
4
|
+
import type { TypedRoot } from '../../../types/modules/typed-root.types';
|
|
4
5
|
/**
|
|
5
6
|
* Trigram similarity conditions (PostgreSQL, `pg_trgm` extension). The column is the left operand,
|
|
6
7
|
* the form a `gin_trgm_ops` / `gist_trgm_ops` index on the column can be used for.
|
|
@@ -13,17 +14,17 @@ export interface TypedWhereSimilarMethods<Entity extends ObjectLiteral> {
|
|
|
13
14
|
* If you had previously WHERE expression defined,
|
|
14
15
|
* calling this function will override previously set WHERE conditions.
|
|
15
16
|
*/
|
|
16
|
-
whereSimilarTyped<Type extends ObjectLiteral = Entity
|
|
17
|
+
whereSimilarTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, term: string | null | undefined, options?: TypedSimilarOptions): this;
|
|
17
18
|
/**
|
|
18
19
|
* Adds new AND WHERE `column % :term` condition in the query builder (PostgreSQL, pg_trgm).
|
|
19
20
|
* A blank term adds no condition.
|
|
20
21
|
*/
|
|
21
|
-
andWhereSimilarTyped<Type extends ObjectLiteral = Entity
|
|
22
|
+
andWhereSimilarTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, term: string | null | undefined, options?: TypedSimilarOptions): this;
|
|
22
23
|
/**
|
|
23
24
|
* Adds new OR WHERE `column % :term` condition in the query builder (PostgreSQL, pg_trgm).
|
|
24
25
|
* A blank term adds no condition.
|
|
25
26
|
*/
|
|
26
|
-
orWhereSimilarTyped<Type extends ObjectLiteral = Entity
|
|
27
|
+
orWhereSimilarTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, term: string | null | undefined, options?: TypedSimilarOptions): this;
|
|
27
28
|
}
|
|
28
29
|
/** Trigram similarity score selection (PostgreSQL, `pg_trgm` extension). */
|
|
29
30
|
export interface TypedSimilarityScoreMethods<Entity extends ObjectLiteral> {
|
|
@@ -34,7 +35,7 @@ export interface TypedSimilarityScoreMethods<Entity extends ObjectLiteral> {
|
|
|
34
35
|
* (`word_similarity(:term, column)`, the score of `column %> :term`).
|
|
35
36
|
* Use a lower-case alias: PostgreSQL folds an unquoted alias in ORDER BY.
|
|
36
37
|
*/
|
|
37
|
-
addSimilarityScoreTyped<Type extends ObjectLiteral = Entity
|
|
38
|
+
addSimilarityScoreTyped<Type extends ObjectLiteral = TypedRoot<Entity>>(selection: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, term: string | null | undefined, alias: string, options?: SimilarityScoreOptions): this;
|
|
38
39
|
}
|
|
39
40
|
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
40
41
|
interface WhereExpressionBuilder extends TypedWhereSimilarMethods<ObjectLiteral> {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ObjectLiteral } from 'typeorm';
|
|
2
2
|
import { DeepUnwrapArray, ProxyColumnValueType } from '../../../types/modules/proxy-callback.types';
|
|
3
3
|
import { TypedWhereArgs, TypeOrDefault, UnsetType } from '../../../types/modules/typed-params.types';
|
|
4
|
+
import type { TypedRoot } from '../../../types/modules/typed-root.types';
|
|
4
5
|
/**
|
|
5
6
|
* Typesafe WHERE conditions: the column comes from an entity property.
|
|
6
7
|
* `Type` defaults to the query builder's entity; with the `strictParams` option (see `TypeormExtensionsConfig`)
|
|
@@ -13,17 +14,17 @@ export interface TypedWhereMethods<Entity extends ObjectLiteral> {
|
|
|
13
14
|
* calling this function will override previously set WHERE conditions.
|
|
14
15
|
* Additionally you can add parameters used in where expression.
|
|
15
16
|
*/
|
|
16
|
-
whereTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType, Operator extends string = string>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity
|
|
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
18
|
/**
|
|
18
19
|
* Adds new AND WHERE condition in the query builder.
|
|
19
20
|
* Additionally you can add parameters used in where expression.
|
|
20
21
|
*/
|
|
21
|
-
andWhereTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType, Operator extends string = string>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity
|
|
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
23
|
/**
|
|
23
24
|
* Adds new OR WHERE condition in the query builder.
|
|
24
25
|
* Additionally you can add parameters used in where expression.
|
|
25
26
|
*/
|
|
26
|
-
orWhereTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType, Operator extends string = string>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity
|
|
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
28
|
}
|
|
28
29
|
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
29
30
|
interface WhereExpressionBuilder extends TypedWhereMethods<ObjectLiteral> {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ObjectLiteral } from 'typeorm';
|
|
2
|
+
import type { UnionCteOptions, UnionOptions, UnionQuery } from '../types/extensions/union.types';
|
|
3
|
+
export interface UnionMethods {
|
|
4
|
+
/**
|
|
5
|
+
* Selects FROM the UNION of `queries`, as `alias`: `FROM ((A) UNION (B)) "alias"`.
|
|
6
|
+
*
|
|
7
|
+
* Unlike pasting `${a.getQuery()} UNION ${b.getQuery()}` and merging `getParameters()`, the
|
|
8
|
+
* parameters of each query are renamed: two queries with a `:status` of their own each keep
|
|
9
|
+
* their value, where a merged object keeps only the last one. A raw SQL string is used as is,
|
|
10
|
+
* its placeholders read the parameters of this builder.
|
|
11
|
+
*/
|
|
12
|
+
fromUnion(queries: readonly UnionQuery[], alias: string, options?: UnionOptions): this;
|
|
13
|
+
/**
|
|
14
|
+
* Adds a common table expression (WITH) that is the UNION of `queries`:
|
|
15
|
+
* `WITH "alias" AS ((A) UNION (B))`. Parameters are renamed as in `fromUnion`.
|
|
16
|
+
*/
|
|
17
|
+
addCommonTableExpressionUnion(queries: readonly UnionQuery[], alias: string, options?: UnionCteOptions): this;
|
|
18
|
+
}
|
|
19
|
+
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
20
|
+
interface SelectQueryBuilder<Entity extends ObjectLiteral> extends UnionMethods {
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const typeorm_1 = require("typeorm");
|
|
4
|
+
const prototype_utils_1 = require("../utils/prototype.utils");
|
|
5
|
+
const parameter_utils_1 = require("../utils/parameter.utils");
|
|
6
|
+
const sql_utils_1 = require("../utils/sql.utils");
|
|
7
|
+
/* eslint-enable @typescript-eslint/no-empty-interface, @typescript-eslint/no-unused-vars */
|
|
8
|
+
// patching
|
|
9
|
+
const extension = {
|
|
10
|
+
prototype: {
|
|
11
|
+
fromUnion(queries, alias, options) {
|
|
12
|
+
return this.from(`(${unionSql(this, 'fromUnion', queries, options)})`, alias);
|
|
13
|
+
},
|
|
14
|
+
addCommonTableExpressionUnion(queries, alias, options) {
|
|
15
|
+
const { all, ...cteOptions } = options !== null && options !== void 0 ? options : {};
|
|
16
|
+
return this.addCommonTableExpression(unionSql(this, 'addCommonTableExpressionUnion', queries, { all }), alias, cteOptions);
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
(0, prototype_utils_1.patchPrototype)(typeorm_1.SelectQueryBuilder, extension);
|
|
21
|
+
// implementation
|
|
22
|
+
/** The UNION of `queries`, with the parameters of each set on `builder` under unique names. */
|
|
23
|
+
function unionSql(builder, methodName, queries, options) {
|
|
24
|
+
if (!queries.length) {
|
|
25
|
+
throw new TypeError(`${methodName}: no queries to union`);
|
|
26
|
+
}
|
|
27
|
+
const sqlite = (0, sql_utils_1.isSqliteLikeDriver)((0, sql_utils_1.getDriverType)(builder));
|
|
28
|
+
const branches = queries.map((query) => {
|
|
29
|
+
const sql = typeof query === 'string' ? query : bindParameters(builder, query);
|
|
30
|
+
if (!sqlite) {
|
|
31
|
+
return `(${sql})`;
|
|
32
|
+
}
|
|
33
|
+
// SQLite takes neither parentheses around a part of a UNION nor an ORDER BY / LIMIT inside one
|
|
34
|
+
// (a query of an entity with a default `orderBy` has an ORDER BY): such a part becomes a subquery.
|
|
35
|
+
// Only such a part: the recursive part of a CTE can't refer to the CTE from a subquery
|
|
36
|
+
return ordersOrLimits(query, sql) ? `SELECT * FROM (${sql})` : sql;
|
|
37
|
+
});
|
|
38
|
+
return branches.join((options === null || options === void 0 ? void 0 : options.all) ? ' UNION ALL ' : ' UNION ');
|
|
39
|
+
}
|
|
40
|
+
const ORDER_OR_LIMIT = /\b(?:ORDER\s+BY|LIMIT|OFFSET)\b/i;
|
|
41
|
+
function ordersOrLimits(query, sql) {
|
|
42
|
+
if (typeof query === 'string' || !('expressionMap' in query)) {
|
|
43
|
+
return ORDER_OR_LIMIT.test(sql);
|
|
44
|
+
}
|
|
45
|
+
const { allOrderBys, limit, offset, take, skip } = query.expressionMap;
|
|
46
|
+
return Object.keys(allOrderBys !== null && allOrderBys !== void 0 ? allOrderBys : {}).length > 0 || [limit, offset, take, skip].some((value) => value !== undefined);
|
|
47
|
+
}
|
|
48
|
+
function bindParameters(builder, query) {
|
|
49
|
+
const [sql, parameters] = (0, parameter_utils_1.withUniqueParameterNames)(query.getQuery(), query.getParameters());
|
|
50
|
+
builder.setParameters(parameters);
|
|
51
|
+
return sql;
|
|
52
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ObjectLiteral, SelectQueryBuilder, WhereExpressionBuilder } from 'typeorm';
|
|
2
|
+
import type { WhereMethods } from '../types/extensions';
|
|
3
|
+
/**
|
|
4
|
+
* `EXISTS` conditions. TypeORM has them on `SelectQueryBuilder` only, and keeps its own there;
|
|
5
|
+
* these add them to `UpdateQueryBuilder` and `DeleteQueryBuilder` with the same SQL. Unlike
|
|
6
|
+
* TypeORM's, they add the subquery's parameters under unique names.
|
|
7
|
+
*/
|
|
8
|
+
export interface WhereExistsMethods {
|
|
9
|
+
/** Sets `WHERE EXISTS (subQuery)`, replacing the WHERE conditions set before. */
|
|
10
|
+
whereExists<SubEntity extends ObjectLiteral>(subQuery: SelectQueryBuilder<SubEntity>): this;
|
|
11
|
+
/** Adds `AND EXISTS (subQuery)`. */
|
|
12
|
+
andWhereExists<SubEntity extends ObjectLiteral>(subQuery: SelectQueryBuilder<SubEntity>): this;
|
|
13
|
+
/** Adds `OR EXISTS (subQuery)`. */
|
|
14
|
+
orWhereExists<SubEntity extends ObjectLiteral>(subQuery: SelectQueryBuilder<SubEntity>): this;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* `NOT EXISTS` conditions: the negation of TypeORM's `whereExists`, with the same subquery SQL.
|
|
18
|
+
* The subquery's parameters are added under unique names, so two subqueries can both use `:status`.
|
|
19
|
+
*/
|
|
20
|
+
export interface WhereNotExistsMethods {
|
|
21
|
+
/** Sets `WHERE NOT EXISTS (subQuery)`, replacing the WHERE conditions set before. */
|
|
22
|
+
whereNotExists<SubEntity extends ObjectLiteral>(subQuery: SelectQueryBuilder<SubEntity>): this;
|
|
23
|
+
/** Adds `AND NOT EXISTS (subQuery)`. */
|
|
24
|
+
andWhereNotExists<SubEntity extends ObjectLiteral>(subQuery: SelectQueryBuilder<SubEntity>): this;
|
|
25
|
+
/** Adds `OR NOT EXISTS (subQuery)`. */
|
|
26
|
+
orWhereNotExists<SubEntity extends ObjectLiteral>(subQuery: SelectQueryBuilder<SubEntity>): this;
|
|
27
|
+
}
|
|
28
|
+
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
29
|
+
interface WhereExpressionBuilder extends WhereExistsMethods, WhereNotExistsMethods {
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
33
|
+
interface SelectQueryBuilder<Entity extends ObjectLiteral> extends WhereNotExistsMethods {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
declare module 'typeorm/query-builder/UpdateQueryBuilder' {
|
|
37
|
+
interface UpdateQueryBuilder<Entity extends ObjectLiteral> extends WhereExistsMethods, WhereNotExistsMethods {
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
declare module 'typeorm/query-builder/DeleteQueryBuilder' {
|
|
41
|
+
interface DeleteQueryBuilder<Entity extends ObjectLiteral> extends WhereExistsMethods, WhereNotExistsMethods {
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
declare module 'typeorm/query-builder/SoftDeleteQueryBuilder' {
|
|
45
|
+
interface SoftDeleteQueryBuilder<Entity extends ObjectLiteral> extends WhereExistsMethods, WhereNotExistsMethods {
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
type SubQuery = SelectQueryBuilder<ObjectLiteral>;
|
|
49
|
+
export declare function attachExists<QB extends WhereExpressionBuilder>(builder: QB, method: WhereMethods, subQuery: SubQuery, negate: boolean): QB;
|
|
50
|
+
export {};
|