typeorm-extensions 1.3.5 → 2.1.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/README.md +12 -10
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.js +2 -2
- package/dist/extensions/cursor-pagination.extension.d.ts +18 -0
- package/dist/extensions/cursor-pagination.extension.js +108 -0
- package/dist/extensions/index.d.ts +7 -0
- package/dist/extensions/index.js +7 -0
- package/dist/extensions/order-by-array-position.extension.d.ts +24 -0
- package/dist/extensions/order-by-array-position.extension.js +18 -0
- package/dist/extensions/order.extension.d.ts +3 -2
- package/dist/extensions/order.extension.js +16 -13
- package/dist/extensions/period-filter.extension.d.ts +29 -0
- package/dist/extensions/period-filter.extension.js +23 -0
- package/dist/extensions/typed/index.d.ts +10 -0
- package/dist/extensions/typed/index.js +10 -0
- package/dist/extensions/typed/typed-distinct/typed-distinct.extension.js +2 -2
- package/dist/extensions/typed/typed-joins/typed-joins.extension.js +2 -1
- package/dist/extensions/typed/typed-order-by/typed-order-by-array-position.extension.d.ts +20 -0
- package/dist/extensions/typed/typed-order-by/typed-order-by-array-position.extension.js +21 -0
- package/dist/extensions/typed/typed-order-by/typed-order-by.extension.d.ts +4 -3
- package/dist/extensions/typed/typed-order-by/typed-order-by.extension.js +7 -6
- package/dist/extensions/typed/typed-returning/typed-returning.extension.d.ts +27 -0
- package/dist/extensions/typed/typed-returning/typed-returning.extension.js +38 -0
- package/dist/extensions/typed/typed-select/typed-select.extension.d.ts +6 -6
- package/dist/extensions/typed/typed-select/typed-select.extension.js +11 -8
- package/dist/extensions/typed/typed-where/typed-period-filter.extension.d.ts +31 -0
- package/dist/extensions/typed/typed-where/typed-period-filter.extension.js +25 -0
- package/dist/extensions/typed/typed-where/typed-where-array.extension.d.ts +68 -0
- package/dist/extensions/typed/typed-where/typed-where-array.extension.js +41 -0
- package/dist/extensions/typed/typed-where/typed-where-ilike.extension.d.ts +62 -0
- package/dist/extensions/typed/typed-where/typed-where-ilike.extension.js +84 -0
- package/dist/extensions/typed/typed-where/typed-where-is-any.extension.d.ts +53 -0
- package/dist/extensions/typed/typed-where/typed-where-is-any.extension.js +38 -0
- package/dist/extensions/typed/typed-where/typed-where-is-distinct-from.extension.d.ts +53 -0
- package/dist/extensions/typed/typed-where/typed-where-is-distinct-from.extension.js +38 -0
- package/dist/extensions/typed/typed-where/typed-where-is-in.extension.d.ts +36 -119
- package/dist/extensions/typed/typed-where/typed-where-is-in.extension.js +14 -29
- package/dist/extensions/typed/typed-where/typed-where-json.extension.d.ts +53 -0
- package/dist/extensions/typed/typed-where/typed-where-json.extension.js +39 -0
- package/dist/extensions/typed/typed-where/typed-where-lower.extension.d.ts +59 -0
- package/dist/extensions/typed/typed-where/typed-where-lower.extension.js +86 -0
- package/dist/extensions/typed/typed-where/typed-where-similar.extension.d.ts +54 -0
- package/dist/extensions/typed/typed-where/typed-where-similar.extension.js +73 -0
- package/dist/extensions/typed/typed-where/typed-where.extension.d.ts +30 -74
- package/dist/extensions/typed/typed-where/typed-where.extension.js +13 -21
- package/dist/extensions/where-array.extension.d.ts +70 -0
- package/dist/extensions/where-array.extension.js +47 -0
- package/dist/extensions/where-is-any.extension.d.ts +142 -0
- package/dist/extensions/where-is-any.extension.js +44 -0
- package/dist/extensions/where-is-distinct-from.extension.d.ts +56 -0
- package/dist/extensions/where-is-distinct-from.extension.js +55 -0
- package/dist/extensions/where-json.extension.d.ts +55 -0
- package/dist/extensions/where-json.extension.js +64 -0
- package/dist/helpers.d.ts +2 -0
- package/dist/helpers.js +23 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/types/extensions/cursor-pagination.types.d.ts +16 -0
- package/dist/types/extensions/cursor-pagination.types.js +2 -0
- package/dist/types/extensions/get-many-with-totals.types.d.ts +3 -1
- package/dist/types/extensions/index.d.ts +4 -0
- package/dist/types/extensions/index.js +4 -0
- package/dist/types/extensions/order.types.d.ts +1 -1
- package/dist/types/extensions/period.types.d.ts +15 -0
- package/dist/types/extensions/period.types.js +2 -0
- package/dist/types/extensions/search.types.d.ts +68 -0
- package/dist/types/extensions/search.types.js +2 -0
- package/dist/types/extensions/typed-order-by.types.d.ts +3 -0
- package/dist/types/extensions/typed-order-by.types.js +2 -0
- package/dist/types/extensions/typed-where.types.d.ts +4 -4
- package/dist/types/extensions/where.types.d.ts +1 -0
- package/dist/types/interfaces/config.interface.d.ts +17 -0
- package/dist/types/interfaces/config.interface.js +2 -0
- package/dist/types/interfaces/cursor-pagination.interface.d.ts +16 -0
- package/dist/types/interfaces/cursor-pagination.interface.js +2 -0
- package/dist/types/interfaces/index.d.ts +3 -0
- package/dist/types/interfaces/index.js +3 -0
- package/dist/types/interfaces/period.interface.d.ts +12 -0
- package/dist/types/interfaces/period.interface.js +2 -0
- package/dist/types/modules/proxy-callback.types.d.ts +50 -3
- package/dist/types/modules/typed-params.types.d.ts +45 -0
- package/dist/types/modules/typed-params.types.js +2 -0
- package/dist/types/util-types/index.d.ts +3 -1
- package/dist/utils/cursor.utils.d.ts +31 -0
- package/dist/utils/cursor.utils.js +130 -0
- package/dist/utils/json-path.utils.d.ts +22 -0
- package/dist/utils/json-path.utils.js +57 -0
- package/dist/utils/order.utils.d.ts +15 -0
- package/dist/utils/order.utils.js +45 -0
- package/dist/utils/period.utils.d.ts +9 -0
- package/dist/utils/period.utils.js +82 -0
- package/dist/utils/proxy-key.utils.d.ts +19 -3
- package/dist/utils/proxy-key.utils.js +40 -15
- package/dist/utils/query-builder.utils.d.ts +48 -0
- package/dist/utils/query-builder.utils.js +257 -0
- package/dist/utils/search.utils.d.ts +27 -0
- package/dist/utils/search.utils.js +83 -0
- package/dist/utils/sql.utils.d.ts +29 -1
- package/dist/utils/sql.utils.js +91 -9
- package/dist/utils/table.utils.d.ts +86 -0
- package/dist/utils/table.utils.js +124 -0
- package/dist/utils/where.utils.d.ts +18 -1
- package/dist/utils/where.utils.js +62 -9
- package/helpers/package.json +7 -0
- package/package.json +5 -4
- package/dist/utils/identifier.utils.d.ts +0 -15
- package/dist/utils/identifier.utils.js +0 -45
|
@@ -7,28 +7,28 @@ declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
|
7
7
|
* Creates SELECT query.
|
|
8
8
|
* Replaces all previous selections if they exist.
|
|
9
9
|
*/
|
|
10
|
-
selectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: KeyProxyCallback<Type>, selectionAliasName?: string,
|
|
10
|
+
selectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: KeyProxyCallback<Type>, selectionAliasName?: string, useQuotes?: boolean): SelectQueryBuilder<Entity>;
|
|
11
11
|
/**
|
|
12
12
|
* Creates SELECT query and selects given data.
|
|
13
13
|
* Replaces all previous selections if they exist.
|
|
14
14
|
*/
|
|
15
|
-
selectTyped(this: SelectQueryBuilder<Entity>, selection: string | KeyHolder, selectionAliasName?: string,
|
|
15
|
+
selectTyped(this: SelectQueryBuilder<Entity>, selection: string | KeyHolder, selectionAliasName?: string, useQuotes?: boolean): SelectQueryBuilder<Entity>;
|
|
16
16
|
/**
|
|
17
17
|
* Creates SELECT query and selects given data.
|
|
18
18
|
* Replaces all previous selections if they exist.
|
|
19
19
|
*/
|
|
20
|
-
selectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: string[] | KeyHolder[] | Array<KeyProxyCallback<Type>>,
|
|
20
|
+
selectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: string[] | KeyHolder[] | Array<KeyProxyCallback<Type>>, useQuotes?: boolean): SelectQueryBuilder<Entity>;
|
|
21
21
|
/**
|
|
22
22
|
* Adds new selection to the SELECT query.
|
|
23
23
|
*/
|
|
24
|
-
addSelectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: KeyProxyCallback<Type>, selectionAliasName?: string,
|
|
24
|
+
addSelectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: KeyProxyCallback<Type>, selectionAliasName?: string, useQuotes?: boolean): SelectQueryBuilder<Entity>;
|
|
25
25
|
/**
|
|
26
26
|
* Adds new selection to the SELECT query.
|
|
27
27
|
*/
|
|
28
|
-
addSelectTyped(this: SelectQueryBuilder<Entity>, selection: string | KeyHolder, selectionAliasName?: string,
|
|
28
|
+
addSelectTyped(this: SelectQueryBuilder<Entity>, selection: string | KeyHolder, selectionAliasName?: string, useQuotes?: boolean): SelectQueryBuilder<Entity>;
|
|
29
29
|
/**
|
|
30
30
|
* Adds new selection to the SELECT query.
|
|
31
31
|
*/
|
|
32
|
-
addSelectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: string[] | KeyHolder[] | Array<KeyProxyCallback<Type>>,
|
|
32
|
+
addSelectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: string[] | KeyHolder[] | Array<KeyProxyCallback<Type>>, useQuotes?: boolean): SelectQueryBuilder<Entity>;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -2,34 +2,37 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const typeorm_1 = require("typeorm");
|
|
4
4
|
const proxy_key_utils_1 = require("../../../utils/proxy-key.utils");
|
|
5
|
+
const query_builder_utils_1 = require("../../../utils/query-builder.utils");
|
|
5
6
|
const prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
6
7
|
// patching
|
|
7
8
|
const extension = {
|
|
8
9
|
prototype: {
|
|
9
|
-
selectTyped(selection, selectionAliasName,
|
|
10
|
+
selectTyped(selection, selectionAliasName, useQuotes) {
|
|
10
11
|
return attachSelectMethod(this, 'select', selection, typeof selectionAliasName === 'string' ? selectionAliasName : undefined, typeof selectionAliasName === 'boolean'
|
|
11
12
|
? selectionAliasName
|
|
12
|
-
:
|
|
13
|
+
: useQuotes);
|
|
13
14
|
},
|
|
14
|
-
addSelectTyped(selection, selectionAliasName,
|
|
15
|
+
addSelectTyped(selection, selectionAliasName, useQuotes) {
|
|
15
16
|
return attachSelectMethod(this, 'addSelect', selection, typeof selectionAliasName === 'string' ? selectionAliasName : undefined, typeof selectionAliasName === 'boolean'
|
|
16
17
|
? selectionAliasName
|
|
17
|
-
:
|
|
18
|
+
: useQuotes);
|
|
18
19
|
},
|
|
19
20
|
},
|
|
20
21
|
};
|
|
21
22
|
(0, prototype_utils_1.patchPrototype)(typeorm_1.SelectQueryBuilder, extension);
|
|
22
23
|
// implementation
|
|
23
|
-
const attachSelectMethod = (query, method, selection, selectionAliasName,
|
|
24
|
+
const attachSelectMethod = (query, method, selection, selectionAliasName, useQuotes) => {
|
|
24
25
|
if (selection instanceof proxy_key_utils_1.KeyHolder) {
|
|
25
|
-
return query[method](selection.toSql(undefined,
|
|
26
|
+
return query[method](selection.toSql(undefined, useQuotes), selectionAliasName);
|
|
26
27
|
}
|
|
27
28
|
if (Array.isArray(selection)) {
|
|
28
|
-
const arrayOfKeys = selection.
|
|
29
|
+
const arrayOfKeys = selection.flatMap((select) => select instanceof proxy_key_utils_1.KeyHolder
|
|
30
|
+
? (0, proxy_key_utils_1.getSqlKeyFromProxyCallback)(select, () => query.alias, useQuotes)
|
|
31
|
+
: (0, query_builder_utils_1.getTypedSelectionKey)(query, select, useQuotes));
|
|
29
32
|
return query[method](arrayOfKeys);
|
|
30
33
|
}
|
|
31
34
|
else if (typeof selection === 'function') {
|
|
32
|
-
const keyArrayOrSingleKey = (0,
|
|
35
|
+
const keyArrayOrSingleKey = (0, query_builder_utils_1.getTypedSelectionKey)(query, selection, useQuotes);
|
|
33
36
|
if (Array.isArray(keyArrayOrSingleKey)) {
|
|
34
37
|
return query[method](keyArrayOrSingleKey);
|
|
35
38
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import '../../period-filter.extension';
|
|
2
|
+
import { ObjectLiteral } from 'typeorm';
|
|
3
|
+
import { DeepUnwrapArray, ProxyColumnValueType } from '../../../types/modules/proxy-callback.types';
|
|
4
|
+
import type { PeriodFilter } from '../../../types/interfaces/period.interface';
|
|
5
|
+
import type { ApplyPeriodOptions } from '../../../types/extensions/period.types';
|
|
6
|
+
export interface TypedPeriodFilterMethods<Entity extends ObjectLiteral> {
|
|
7
|
+
/**
|
|
8
|
+
* Adds AND WHERE conditions for a period on an entity property:
|
|
9
|
+
* `column >= :periodFrom AND column <= :periodTo`.
|
|
10
|
+
* Missing, `null` or empty ends are skipped, so an empty filter adds nothing.
|
|
11
|
+
* Both ends are inclusive unless `options.includeFrom` / `options.includeTo` is `false`.
|
|
12
|
+
* A date-only string (`'2024-01-31'`) stands for the whole day: `periodTo: '2024-01-31'` → `column < '2024-02-01'`.
|
|
13
|
+
*/
|
|
14
|
+
applyPeriodFilterTyped<Type extends ObjectLiteral = Entity>(selection: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, periodFilter: PeriodFilter | null | undefined, options?: ApplyPeriodOptions): this;
|
|
15
|
+
}
|
|
16
|
+
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
17
|
+
interface WhereExpressionBuilder extends TypedPeriodFilterMethods<ObjectLiteral> {
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
21
|
+
interface SelectQueryBuilder<Entity extends ObjectLiteral> extends TypedPeriodFilterMethods<Entity> {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
declare module 'typeorm/query-builder/UpdateQueryBuilder' {
|
|
25
|
+
interface UpdateQueryBuilder<Entity extends ObjectLiteral> extends TypedPeriodFilterMethods<Entity> {
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
declare module 'typeorm/query-builder/DeleteQueryBuilder' {
|
|
29
|
+
interface DeleteQueryBuilder<Entity extends ObjectLiteral> extends TypedPeriodFilterMethods<Entity> {
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("../../period-filter.extension");
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
const query_builder_utils_1 = require("../../../utils/query-builder.utils");
|
|
6
|
+
const prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
7
|
+
const period_utils_1 = require("../../../utils/period.utils");
|
|
8
|
+
/* eslint-enable @typescript-eslint/no-empty-interface */
|
|
9
|
+
// patching
|
|
10
|
+
const extension = {
|
|
11
|
+
prototype: {
|
|
12
|
+
applyPeriodFilterTyped(selection, periodFilter, options) {
|
|
13
|
+
const column = (0, query_builder_utils_1.getTypedSingleColumnKey)(this, selection, 'applyPeriodFilterTyped', { asTimestamp: true });
|
|
14
|
+
return (0, period_utils_1.attachPeriodFilter)(this, column, periodFilter, options);
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
const queryBuilders = [
|
|
19
|
+
typeorm_1.SelectQueryBuilder,
|
|
20
|
+
typeorm_1.UpdateQueryBuilder,
|
|
21
|
+
typeorm_1.DeleteQueryBuilder,
|
|
22
|
+
];
|
|
23
|
+
queryBuilders.forEach((builder) => {
|
|
24
|
+
(0, prototype_utils_1.patchPrototype)(builder, extension);
|
|
25
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import '../../where-array.extension';
|
|
2
|
+
import { ObjectLiteral } from 'typeorm';
|
|
3
|
+
import { DeepUnwrapArray, ProxyColumnValueType } from '../../../types/modules/proxy-callback.types';
|
|
4
|
+
import { ArgsType } from '../../../types/util-types';
|
|
5
|
+
/**
|
|
6
|
+
* Typesafe conditions on PostgreSQL array columns: the column comes from an entity property.
|
|
7
|
+
* See {@link WhereArrayMethods}.
|
|
8
|
+
*/
|
|
9
|
+
export interface TypedWhereArrayMethods<Entity extends ObjectLiteral> {
|
|
10
|
+
/**
|
|
11
|
+
* Sets WHERE `column @> :values` condition (PostgreSQL): the array column contains every value.
|
|
12
|
+
* If you had previously WHERE expression defined,
|
|
13
|
+
* calling this function will override previously set WHERE conditions.
|
|
14
|
+
*/
|
|
15
|
+
whereArrayContainsTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
16
|
+
/**
|
|
17
|
+
* Adds new AND WHERE `column @> :values` condition (PostgreSQL): the array column contains every value.
|
|
18
|
+
*/
|
|
19
|
+
andWhereArrayContainsTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
20
|
+
/**
|
|
21
|
+
* Adds new OR WHERE `column @> :values` condition (PostgreSQL): the array column contains every value.
|
|
22
|
+
*/
|
|
23
|
+
orWhereArrayContainsTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
24
|
+
/**
|
|
25
|
+
* Sets WHERE `column <@ :values` condition (PostgreSQL): every element of the array column is one of the values.
|
|
26
|
+
* If you had previously WHERE expression defined,
|
|
27
|
+
* calling this function will override previously set WHERE conditions.
|
|
28
|
+
*/
|
|
29
|
+
whereArrayContainedByTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
30
|
+
/**
|
|
31
|
+
* Adds new AND WHERE `column <@ :values` condition (PostgreSQL): every element of the array column is one of the values.
|
|
32
|
+
*/
|
|
33
|
+
andWhereArrayContainedByTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
34
|
+
/**
|
|
35
|
+
* Adds new OR WHERE `column <@ :values` condition (PostgreSQL): every element of the array column is one of the values.
|
|
36
|
+
*/
|
|
37
|
+
orWhereArrayContainedByTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
38
|
+
/**
|
|
39
|
+
* Sets WHERE `column && :values` condition (PostgreSQL): the array column has at least one of the values.
|
|
40
|
+
* If you had previously WHERE expression defined,
|
|
41
|
+
* calling this function will override previously set WHERE conditions.
|
|
42
|
+
*/
|
|
43
|
+
whereArrayOverlapsTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
44
|
+
/**
|
|
45
|
+
* Adds new AND WHERE `column && :values` condition (PostgreSQL): the array column has at least one of the values.
|
|
46
|
+
*/
|
|
47
|
+
andWhereArrayOverlapsTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
48
|
+
/**
|
|
49
|
+
* Adds new OR WHERE `column && :values` condition (PostgreSQL): the array column has at least one of the values.
|
|
50
|
+
*/
|
|
51
|
+
orWhereArrayOverlapsTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, values: ArgsType, arrayType?: string): this;
|
|
52
|
+
}
|
|
53
|
+
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
54
|
+
interface WhereExpressionBuilder extends TypedWhereArrayMethods<ObjectLiteral> {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
58
|
+
interface SelectQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereArrayMethods<Entity> {
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
declare module 'typeorm/query-builder/UpdateQueryBuilder' {
|
|
62
|
+
interface UpdateQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereArrayMethods<Entity> {
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
declare module 'typeorm/query-builder/DeleteQueryBuilder' {
|
|
66
|
+
interface DeleteQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereArrayMethods<Entity> {
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("../../where-array.extension");
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
const query_builder_utils_1 = require("../../../utils/query-builder.utils");
|
|
6
|
+
const prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
7
|
+
/* eslint-enable @typescript-eslint/no-empty-interface */
|
|
8
|
+
// patching
|
|
9
|
+
const createWhereArrayTypedMethod = (method) => function (where, values, arrayType) {
|
|
10
|
+
return attachWhereArrayTyped(this, method, where, values, arrayType);
|
|
11
|
+
};
|
|
12
|
+
const extension = {
|
|
13
|
+
prototype: {
|
|
14
|
+
whereArrayContainsTyped: createWhereArrayTypedMethod('whereArrayContains'),
|
|
15
|
+
andWhereArrayContainsTyped: createWhereArrayTypedMethod('andWhereArrayContains'),
|
|
16
|
+
orWhereArrayContainsTyped: createWhereArrayTypedMethod('orWhereArrayContains'),
|
|
17
|
+
whereArrayContainedByTyped: createWhereArrayTypedMethod('whereArrayContainedBy'),
|
|
18
|
+
andWhereArrayContainedByTyped: createWhereArrayTypedMethod('andWhereArrayContainedBy'),
|
|
19
|
+
orWhereArrayContainedByTyped: createWhereArrayTypedMethod('orWhereArrayContainedBy'),
|
|
20
|
+
whereArrayOverlapsTyped: createWhereArrayTypedMethod('whereArrayOverlaps'),
|
|
21
|
+
andWhereArrayOverlapsTyped: createWhereArrayTypedMethod('andWhereArrayOverlaps'),
|
|
22
|
+
orWhereArrayOverlapsTyped: createWhereArrayTypedMethod('orWhereArrayOverlaps'),
|
|
23
|
+
},
|
|
24
|
+
};
|
|
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
|
+
});
|
|
33
|
+
// implementation
|
|
34
|
+
function attachWhereArrayTyped(builder, method, where, values, arrayType) {
|
|
35
|
+
if (typeof where !== 'function') {
|
|
36
|
+
return builder;
|
|
37
|
+
}
|
|
38
|
+
const key = (0, query_builder_utils_1.getTypedSingleColumnKey)(builder, where, `${method}Typed`);
|
|
39
|
+
// .andWhereArrayContains(`"table"."column"`, ['value'])
|
|
40
|
+
return builder[method](key, values, arrayType);
|
|
41
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ObjectLiteral } from 'typeorm';
|
|
2
|
+
import { DeepUnwrapArray, ProxyColumnValueType } from '../../../types/modules/proxy-callback.types';
|
|
3
|
+
import type { SearchSelector, TypedILikeOptions, TypedSearchOptions } from '../../../types/extensions/search.types';
|
|
4
|
+
/**
|
|
5
|
+
* Case-insensitive search methods: `ILIKE` on PostgreSQL, `LIKE` on MySQL / MariaDB and SQLite.
|
|
6
|
+
* `%`, `_` and `\` in the value are escaped, and a blank value adds no condition.
|
|
7
|
+
*/
|
|
8
|
+
export interface TypedWhereILikeMethods<Entity extends ObjectLiteral> {
|
|
9
|
+
/**
|
|
10
|
+
* Sets WHERE `column ILIKE :pattern` condition in the query builder,
|
|
11
|
+
* `%value%` by default (`options.match`). `%`, `_` and `\` in the value match themselves.
|
|
12
|
+
* `null`, `undefined` or a blank value adds no condition (previous conditions are kept).
|
|
13
|
+
* If you had previously WHERE expression defined,
|
|
14
|
+
* calling this function will override previously set WHERE conditions.
|
|
15
|
+
*/
|
|
16
|
+
whereILikeTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: string | null | undefined, options?: TypedILikeOptions): this;
|
|
17
|
+
/**
|
|
18
|
+
* Adds new AND WHERE `column ILIKE :pattern` condition in the query builder.
|
|
19
|
+
* `null`, `undefined` or a blank value adds no condition.
|
|
20
|
+
*/
|
|
21
|
+
andWhereILikeTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: string | null | undefined, options?: TypedILikeOptions): this;
|
|
22
|
+
/**
|
|
23
|
+
* Adds new OR WHERE `column ILIKE :pattern` condition in the query builder.
|
|
24
|
+
* `null`, `undefined` or a blank value adds no condition.
|
|
25
|
+
*/
|
|
26
|
+
orWhereILikeTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: string | null | undefined, options?: TypedILikeOptions): this;
|
|
27
|
+
/**
|
|
28
|
+
* Sets WHERE `(col1 ILIKE :pattern OR col2 ILIKE :pattern …)` condition in the query builder:
|
|
29
|
+
* one group, one parameter for every column. A selector is a typed callback (it may select
|
|
30
|
+
* several columns) or a raw expression `{ sql: '…' }`, which is put in parentheses.
|
|
31
|
+
* A value shorter than `options.minLength` (default 1, after trimming) adds no condition.
|
|
32
|
+
* If you had previously WHERE expression defined,
|
|
33
|
+
* calling this function will override previously set WHERE conditions.
|
|
34
|
+
*/
|
|
35
|
+
whereSearchTyped<Type extends ObjectLiteral = Entity>(selectors: ReadonlyArray<SearchSelector<Type>>, value: string | null | undefined, options?: TypedSearchOptions): this;
|
|
36
|
+
/**
|
|
37
|
+
* Adds new AND WHERE `(col1 ILIKE :pattern OR col2 ILIKE :pattern …)` condition in the query builder.
|
|
38
|
+
* A value shorter than `options.minLength` (default 1, after trimming) adds no condition.
|
|
39
|
+
*/
|
|
40
|
+
andWhereSearchTyped<Type extends ObjectLiteral = Entity>(selectors: ReadonlyArray<SearchSelector<Type>>, value: string | null | undefined, options?: TypedSearchOptions): this;
|
|
41
|
+
/**
|
|
42
|
+
* Adds new OR WHERE `(col1 ILIKE :pattern OR col2 ILIKE :pattern …)` condition in the query builder.
|
|
43
|
+
* A value shorter than `options.minLength` (default 1, after trimming) adds no condition.
|
|
44
|
+
*/
|
|
45
|
+
orWhereSearchTyped<Type extends ObjectLiteral = Entity>(selectors: ReadonlyArray<SearchSelector<Type>>, value: string | null | undefined, options?: TypedSearchOptions): this;
|
|
46
|
+
}
|
|
47
|
+
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
48
|
+
interface WhereExpressionBuilder extends TypedWhereILikeMethods<ObjectLiteral> {
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
52
|
+
interface SelectQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereILikeMethods<Entity> {
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
declare module 'typeorm/query-builder/UpdateQueryBuilder' {
|
|
56
|
+
interface UpdateQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereILikeMethods<Entity> {
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
declare module 'typeorm/query-builder/DeleteQueryBuilder' {
|
|
60
|
+
interface DeleteQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereILikeMethods<Entity> {
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const typeorm_1 = require("typeorm");
|
|
4
|
+
const query_builder_utils_1 = require("../../../utils/query-builder.utils");
|
|
5
|
+
const prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
6
|
+
const sql_utils_1 = require("../../../utils/sql.utils");
|
|
7
|
+
const search_utils_1 = require("../../../utils/search.utils");
|
|
8
|
+
/* eslint-enable @typescript-eslint/no-empty-interface */
|
|
9
|
+
// patching
|
|
10
|
+
const createWhereILikeTypedMethod = (method) => function (where, value, options) {
|
|
11
|
+
if (typeof where !== 'function') {
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
const methodName = `${method}ILikeTyped`;
|
|
15
|
+
// resolve the column first: a wrong selector throws even for a blank value
|
|
16
|
+
const column = (0, query_builder_utils_1.getTypedSingleColumnKey)(this, where, methodName);
|
|
17
|
+
const term = (0, search_utils_1.toSearchTerm)(value, methodName);
|
|
18
|
+
if (term === undefined) {
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
return attachILike(this, method, [column], term, options);
|
|
22
|
+
};
|
|
23
|
+
const createWhereSearchTypedMethod = (method) => function (selectors, value, options) {
|
|
24
|
+
var _a;
|
|
25
|
+
const methodName = `${method}SearchTyped`;
|
|
26
|
+
// resolve the columns first: a wrong selector throws even for a blank value
|
|
27
|
+
const columns = getSearchColumns(this, selectors, methodName);
|
|
28
|
+
const term = (0, search_utils_1.toSearchTerm)(value, methodName);
|
|
29
|
+
const minLength = (_a = options === null || options === void 0 ? void 0 : options.minLength) !== null && _a !== void 0 ? _a : 1;
|
|
30
|
+
if (term === undefined || term.length < minLength) {
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
return attachILike(this, method, columns, term, options);
|
|
34
|
+
};
|
|
35
|
+
const extension = {
|
|
36
|
+
prototype: {
|
|
37
|
+
whereILikeTyped: createWhereILikeTypedMethod('where'),
|
|
38
|
+
andWhereILikeTyped: createWhereILikeTypedMethod('andWhere'),
|
|
39
|
+
orWhereILikeTyped: createWhereILikeTypedMethod('orWhere'),
|
|
40
|
+
whereSearchTyped: createWhereSearchTypedMethod('where'),
|
|
41
|
+
andWhereSearchTyped: createWhereSearchTypedMethod('andWhere'),
|
|
42
|
+
orWhereSearchTyped: createWhereSearchTypedMethod('orWhere'),
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
const queryBuilders = [
|
|
46
|
+
typeorm_1.SelectQueryBuilder,
|
|
47
|
+
typeorm_1.UpdateQueryBuilder,
|
|
48
|
+
typeorm_1.DeleteQueryBuilder,
|
|
49
|
+
];
|
|
50
|
+
queryBuilders.forEach((builder) => {
|
|
51
|
+
(0, prototype_utils_1.patchPrototype)(builder, extension);
|
|
52
|
+
});
|
|
53
|
+
// implementation
|
|
54
|
+
/** Quoted columns and raw expressions of the search selectors, in order. */
|
|
55
|
+
function getSearchColumns(builder, selectors, methodName) {
|
|
56
|
+
if (!Array.isArray(selectors) || selectors.length === 0) {
|
|
57
|
+
// no columns to search in: matching nothing or everything silently would hide the bug
|
|
58
|
+
throw new TypeError(`${methodName} expects a non-empty array of columns to search in`);
|
|
59
|
+
}
|
|
60
|
+
return selectors.flatMap((selector) => {
|
|
61
|
+
if (typeof selector === 'function') {
|
|
62
|
+
return (0, query_builder_utils_1.getTypedColumnKey)(builder, selector);
|
|
63
|
+
}
|
|
64
|
+
if (selector && typeof selector === 'object' && typeof selector.sql === 'string' && selector.sql.trim()) {
|
|
65
|
+
// in parentheses: the expression may have operators that bind looser than ILIKE
|
|
66
|
+
return `(${selector.sql})`;
|
|
67
|
+
}
|
|
68
|
+
throw new TypeError(`${methodName} expects a typed callback or { sql: string }, got ${JSON.stringify(selector)}`);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* `column ILIKE :pattern` for one column, `(col1 ILIKE :pattern OR col2 ILIKE :pattern)` for several:
|
|
73
|
+
* all the columns share one parameter.
|
|
74
|
+
*/
|
|
75
|
+
function attachILike(builder, method, columns, term, options) {
|
|
76
|
+
const { match = 'contains', escape = true, unaccent } = options !== null && options !== void 0 ? options : {};
|
|
77
|
+
const pattern = (0, search_utils_1.toLikePattern)(term, match, escape);
|
|
78
|
+
const unaccentFunction = (0, search_utils_1.toUnaccentFunction)(unaccent);
|
|
79
|
+
const driver = (0, sql_utils_1.getDriverType)(builder);
|
|
80
|
+
const paramName = (0, sql_utils_1.createUniqueParameterName)(method);
|
|
81
|
+
const conditions = columns.map((column) => (0, search_utils_1.buildILikeCondition)(driver, column, `:${paramName}`, unaccentFunction));
|
|
82
|
+
const condition = conditions.length === 1 ? conditions[0] : `(${conditions.join(' OR ')})`;
|
|
83
|
+
return builder[method](condition, { [paramName]: pattern });
|
|
84
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import '../../where-is-any.extension';
|
|
2
|
+
import { ObjectLiteral } from 'typeorm';
|
|
3
|
+
import { DeepUnwrapArray, ProxyColumnValueType } from '../../../types/modules/proxy-callback.types';
|
|
4
|
+
import { TypedArrayArg, TypeOrDefault, UnsetType } from '../../../types/modules/typed-params.types';
|
|
5
|
+
export interface TypedWhereIsAnyMethods<Entity extends ObjectLiteral> {
|
|
6
|
+
/**
|
|
7
|
+
* Sets WHERE `column = ANY(:array)` condition in the query builder (PostgreSQL).
|
|
8
|
+
* The array is bound as a single parameter instead of one parameter per value.
|
|
9
|
+
* `arrayType` (e.g. `'uuid[]'`) casts the parameter: `= ANY(CAST(:array AS uuid[]))`.
|
|
10
|
+
* If you had previously WHERE expression defined,
|
|
11
|
+
* calling this function will override previously set WHERE conditions.
|
|
12
|
+
*/
|
|
13
|
+
whereIsAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity>>) => Value, array?: TypedArrayArg<Type, Value>, arrayType?: string): this;
|
|
14
|
+
/**
|
|
15
|
+
* Adds new AND WHERE `column = ANY(:array)` condition in the query builder (PostgreSQL).
|
|
16
|
+
*/
|
|
17
|
+
andWhereIsAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity>>) => Value, array?: TypedArrayArg<Type, Value>, arrayType?: string): this;
|
|
18
|
+
/**
|
|
19
|
+
* Adds new OR WHERE `column = ANY(:array)` condition in the query builder (PostgreSQL).
|
|
20
|
+
*/
|
|
21
|
+
orWhereIsAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity>>) => Value, array?: TypedArrayArg<Type, Value>, arrayType?: string): this;
|
|
22
|
+
/**
|
|
23
|
+
* Sets WHERE `column <> ALL(:array)` condition in the query builder (PostgreSQL):
|
|
24
|
+
* the column differs from every value of the array.
|
|
25
|
+
* If you had previously WHERE expression defined,
|
|
26
|
+
* calling this function will override previously set WHERE conditions.
|
|
27
|
+
*/
|
|
28
|
+
whereIsNotAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity>>) => Value, array?: TypedArrayArg<Type, Value>, arrayType?: string): this;
|
|
29
|
+
/**
|
|
30
|
+
* Adds new AND WHERE `column <> ALL(:array)` condition in the query builder (PostgreSQL).
|
|
31
|
+
*/
|
|
32
|
+
andWhereIsNotAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity>>) => Value, array?: TypedArrayArg<Type, Value>, arrayType?: string): this;
|
|
33
|
+
/**
|
|
34
|
+
* Adds new OR WHERE `column <> ALL(:array)` condition in the query builder (PostgreSQL).
|
|
35
|
+
*/
|
|
36
|
+
orWhereIsNotAnyTyped<Type extends ObjectLiteral = UnsetType, Value extends ProxyColumnValueType = ProxyColumnValueType>(where: (proxy: DeepUnwrapArray<TypeOrDefault<Type, Entity>>) => Value, array?: TypedArrayArg<Type, Value>, arrayType?: string): this;
|
|
37
|
+
}
|
|
38
|
+
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
39
|
+
interface WhereExpressionBuilder extends TypedWhereIsAnyMethods<ObjectLiteral> {
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
43
|
+
interface SelectQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereIsAnyMethods<Entity> {
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
declare module 'typeorm/query-builder/UpdateQueryBuilder' {
|
|
47
|
+
interface UpdateQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereIsAnyMethods<Entity> {
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
declare module 'typeorm/query-builder/DeleteQueryBuilder' {
|
|
51
|
+
interface DeleteQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereIsAnyMethods<Entity> {
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("../../where-is-any.extension");
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
const query_builder_utils_1 = require("../../../utils/query-builder.utils");
|
|
6
|
+
const prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
7
|
+
/* eslint-enable @typescript-eslint/no-empty-interface */
|
|
8
|
+
// patching
|
|
9
|
+
const createWhereIsAnyTypedMethod = (method) => function (where, array, arrayType) {
|
|
10
|
+
return attachWhereIsAnyTyped(this, method, where, array, arrayType);
|
|
11
|
+
};
|
|
12
|
+
const extension = {
|
|
13
|
+
prototype: {
|
|
14
|
+
whereIsAnyTyped: createWhereIsAnyTypedMethod('whereIsAny'),
|
|
15
|
+
andWhereIsAnyTyped: createWhereIsAnyTypedMethod('andWhereIsAny'),
|
|
16
|
+
orWhereIsAnyTyped: createWhereIsAnyTypedMethod('orWhereIsAny'),
|
|
17
|
+
whereIsNotAnyTyped: createWhereIsAnyTypedMethod('whereIsNotAny'),
|
|
18
|
+
andWhereIsNotAnyTyped: createWhereIsAnyTypedMethod('andWhereIsNotAny'),
|
|
19
|
+
orWhereIsNotAnyTyped: createWhereIsAnyTypedMethod('orWhereIsNotAny'),
|
|
20
|
+
},
|
|
21
|
+
};
|
|
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
|
+
});
|
|
30
|
+
// implementation
|
|
31
|
+
function attachWhereIsAnyTyped(builder, method, where, array, arrayType) {
|
|
32
|
+
if (typeof where !== 'function') {
|
|
33
|
+
return builder;
|
|
34
|
+
}
|
|
35
|
+
const key = (0, query_builder_utils_1.getTypedSingleColumnKey)(builder, where, `${method}Typed`, { value: array });
|
|
36
|
+
// .andWhere(`"table"."column" = ANY(:param)`, { param: ['value'] })
|
|
37
|
+
return builder[method](key, array, arrayType);
|
|
38
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import '../../where-is-distinct-from.extension';
|
|
2
|
+
import { ObjectLiteral } from 'typeorm';
|
|
3
|
+
import { DeepUnwrapArray, ProxyColumnValueType } from '../../../types/modules/proxy-callback.types';
|
|
4
|
+
/**
|
|
5
|
+
* Typesafe null-safe comparisons: the column comes from an entity property.
|
|
6
|
+
* See {@link WhereDistinctMethods}.
|
|
7
|
+
*/
|
|
8
|
+
export interface TypedWhereDistinctMethods<Entity extends ObjectLiteral> {
|
|
9
|
+
/**
|
|
10
|
+
* Sets WHERE `column IS DISTINCT FROM :value` condition: the column differs from the value, `NULL` included.
|
|
11
|
+
* If you had previously WHERE expression defined,
|
|
12
|
+
* calling this function will override previously set WHERE conditions.
|
|
13
|
+
*/
|
|
14
|
+
whereIsDistinctFromTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: unknown): this;
|
|
15
|
+
/**
|
|
16
|
+
* Adds new AND WHERE `column IS DISTINCT FROM :value` condition: the column differs from the value, `NULL` included.
|
|
17
|
+
*/
|
|
18
|
+
andWhereIsDistinctFromTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: unknown): this;
|
|
19
|
+
/**
|
|
20
|
+
* Adds new OR WHERE `column IS DISTINCT FROM :value` condition: the column differs from the value, `NULL` included.
|
|
21
|
+
*/
|
|
22
|
+
orWhereIsDistinctFromTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: unknown): this;
|
|
23
|
+
/**
|
|
24
|
+
* Sets WHERE `column IS NOT DISTINCT FROM :value` condition: the column equals the value, `NULL` included.
|
|
25
|
+
* If you had previously WHERE expression defined,
|
|
26
|
+
* calling this function will override previously set WHERE conditions.
|
|
27
|
+
*/
|
|
28
|
+
whereIsNotDistinctFromTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: unknown): this;
|
|
29
|
+
/**
|
|
30
|
+
* Adds new AND WHERE `column IS NOT DISTINCT FROM :value` condition: the column equals the value, `NULL` included.
|
|
31
|
+
*/
|
|
32
|
+
andWhereIsNotDistinctFromTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: unknown): this;
|
|
33
|
+
/**
|
|
34
|
+
* Adds new OR WHERE `column IS NOT DISTINCT FROM :value` condition: the column equals the value, `NULL` included.
|
|
35
|
+
*/
|
|
36
|
+
orWhereIsNotDistinctFromTyped<Type extends ObjectLiteral = Entity>(where: (proxy: DeepUnwrapArray<Type>) => ProxyColumnValueType, value: unknown): this;
|
|
37
|
+
}
|
|
38
|
+
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
39
|
+
interface WhereExpressionBuilder extends TypedWhereDistinctMethods<ObjectLiteral> {
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
43
|
+
interface SelectQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereDistinctMethods<Entity> {
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
declare module 'typeorm/query-builder/UpdateQueryBuilder' {
|
|
47
|
+
interface UpdateQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereDistinctMethods<Entity> {
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
declare module 'typeorm/query-builder/DeleteQueryBuilder' {
|
|
51
|
+
interface DeleteQueryBuilder<Entity extends ObjectLiteral> extends TypedWhereDistinctMethods<Entity> {
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("../../where-is-distinct-from.extension");
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
const query_builder_utils_1 = require("../../../utils/query-builder.utils");
|
|
6
|
+
const prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
7
|
+
/* eslint-enable @typescript-eslint/no-empty-interface */
|
|
8
|
+
// patching
|
|
9
|
+
const createWhereDistinctTypedMethod = (method) => function (where, value) {
|
|
10
|
+
return attachWhereDistinctTyped(this, method, where, value);
|
|
11
|
+
};
|
|
12
|
+
const extension = {
|
|
13
|
+
prototype: {
|
|
14
|
+
whereIsDistinctFromTyped: createWhereDistinctTypedMethod('whereIsDistinctFrom'),
|
|
15
|
+
andWhereIsDistinctFromTyped: createWhereDistinctTypedMethod('andWhereIsDistinctFrom'),
|
|
16
|
+
orWhereIsDistinctFromTyped: createWhereDistinctTypedMethod('orWhereIsDistinctFrom'),
|
|
17
|
+
whereIsNotDistinctFromTyped: createWhereDistinctTypedMethod('whereIsNotDistinctFrom'),
|
|
18
|
+
andWhereIsNotDistinctFromTyped: createWhereDistinctTypedMethod('andWhereIsNotDistinctFrom'),
|
|
19
|
+
orWhereIsNotDistinctFromTyped: createWhereDistinctTypedMethod('orWhereIsNotDistinctFrom'),
|
|
20
|
+
},
|
|
21
|
+
};
|
|
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
|
+
});
|
|
30
|
+
// implementation
|
|
31
|
+
function attachWhereDistinctTyped(builder, method, where, value) {
|
|
32
|
+
if (typeof where !== 'function') {
|
|
33
|
+
return builder;
|
|
34
|
+
}
|
|
35
|
+
const key = (0, query_builder_utils_1.getTypedSingleColumnKey)(builder, where, `${method}Typed`, { value });
|
|
36
|
+
// .andWhereIsDistinctFrom(`"table"."column"`, value)
|
|
37
|
+
return builder[method](key, value);
|
|
38
|
+
}
|