typeorm-extensions 1.2.6 → 1.3.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 +11 -3
- package/dist/extensions/get-many-with-totals.extension.d.ts +1 -16
- package/dist/extensions/get-many-with-totals.extension.js +22 -8
- package/dist/extensions/index.d.ts +1 -0
- package/dist/extensions/index.js +1 -0
- package/dist/extensions/order.extension.d.ts +1 -15
- package/dist/extensions/order.extension.js +39 -21
- package/dist/extensions/pagination.extension.d.ts +1 -10
- package/dist/extensions/pagination.extension.js +17 -4
- package/dist/extensions/typed/index.d.ts +1 -2
- package/dist/extensions/typed/index.js +1 -3
- package/dist/extensions/typed/typed-distinct/typed-distinct.extension.d.ts +1 -14
- package/dist/extensions/typed/typed-distinct/typed-distinct.extension.js +3 -1
- package/dist/extensions/typed/typed-joins/typed-joins.extension.d.ts +1 -10
- package/dist/extensions/typed/typed-joins/typed-joins.extension.js +3 -1
- package/dist/extensions/typed/typed-order-by/typed-order-by.extension.d.ts +1 -17
- package/dist/extensions/typed/typed-order-by/typed-order-by.extension.js +6 -5
- package/dist/extensions/typed/typed-select/typed-select.extension.d.ts +1 -33
- package/dist/extensions/typed/typed-select/typed-select.extension.js +17 -9
- package/dist/extensions/typed/typed-where/typed-where-is-in.extension.d.ts +2 -0
- package/dist/extensions/typed/typed-where/typed-where-is-in.extension.js +55 -0
- package/dist/extensions/typed/typed-where/typed-where.extension.d.ts +1 -89
- package/dist/extensions/typed/typed-where/typed-where.extension.js +32 -16
- package/dist/extensions/where-is-in.extension.d.ts +1 -0
- package/dist/extensions/where-is-in.extension.js +52 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types/extensions/get-many-with-totals.types.d.ts +10 -0
- package/dist/types/extensions/index.d.ts +4 -0
- package/dist/types/extensions/index.js +20 -0
- package/dist/types/extensions/order.types.d.ts +6 -0
- package/dist/types/extensions/pagination.types.d.ts +3 -0
- package/dist/types/extensions/pagination.types.js +2 -0
- package/dist/types/extensions/typed-where.types.d.ts +7 -0
- package/dist/types/extensions/typed-where.types.js +2 -0
- package/dist/types/extensions/where.types.d.ts +2 -0
- package/dist/types/extensions/where.types.js +2 -0
- package/dist/types/interfaces/ordering.interface.d.ts +1 -1
- package/dist/types/modules/proxy-callback.types.d.ts +7 -0
- package/dist/types/modules/proxy-callback.types.js +2 -0
- package/dist/types/util-types/index.d.ts +1 -0
- package/dist/types/util-types/index.js +1 -0
- package/dist/utils/common.utils.d.ts +1 -0
- package/dist/utils/common.utils.js +11 -1
- package/dist/utils/prototype.utils.d.ts +5 -0
- package/dist/utils/prototype.utils.js +10 -0
- package/dist/utils/proxy-key.utils.d.ts +7 -5
- package/dist/utils/proxy-key.utils.js +25 -14
- package/dist/utils/sql.utils.d.ts +1 -0
- package/dist/utils/sql.utils.js +7 -1
- package/dist/utils/where.utils.d.ts +6 -0
- package/dist/utils/where.utils.js +35 -0
- package/package.json +3 -3
- package/dist/extensions/ordering.extension.js +0 -48
- package/dist/extensions/typed/typeorm-querybuilder.types.d.ts +0 -22
- package/dist/extensions/typed/typeorm-querybuilder.types.js +0 -56
- package/dist/extensions/typed/typeorm.types.d.ts +0 -17
- package/dist/types/modules/proxy-types/proxy-callback.types.d.ts +0 -6
- package/dist/utils/string.utils.js +0 -11
- /package/dist/{extensions/typed/typeorm.types.js → types/extensions/get-many-with-totals.types.js} +0 -0
- /package/dist/types/{modules/proxy-types/proxy-callback.types.js → extensions/order.types.js} +0 -0
package/README.md
CHANGED
|
@@ -35,16 +35,17 @@ const query = myDataSource
|
|
|
35
35
|
.createQueryBuilder()
|
|
36
36
|
.from(UserEntity, 'users')
|
|
37
37
|
// Join relation defined in entity model
|
|
38
|
-
.leftJoinTyped(user => user.
|
|
38
|
+
.leftJoinTyped(user => user.images, 'images')
|
|
39
39
|
// Select type-safe properties
|
|
40
40
|
.selectTyped(user => ([
|
|
41
41
|
id: user.id,
|
|
42
42
|
name: user.name,
|
|
43
43
|
email: user.email,
|
|
44
44
|
]))
|
|
45
|
-
.whereTyped(user => user.name, 'ILIKE
|
|
45
|
+
.whereTyped(user => user.name, 'ILIKE', { search: 'John' })
|
|
46
|
+
.andWhereTyped(user => user.metadata, ` ->> 'jsonField' =`, { value: 'some-value' })
|
|
46
47
|
// Order by type-safe own and relation properties
|
|
47
|
-
.orderByTyped(user => user.
|
|
48
|
+
.orderByTyped(user => user.images.url, 'ASC', 'NULLS LAST')
|
|
48
49
|
// Use pagination as simple as that
|
|
49
50
|
.applyPaginationFilter({ page: 1, pageSize: 10 }, { useTakeAndSkip: true });
|
|
50
51
|
```
|
|
@@ -52,3 +53,10 @@ const query = myDataSource
|
|
|
52
53
|
## Documentation
|
|
53
54
|
|
|
54
55
|
For more information, please refer to the [documentation](https://koenigstag.github.io/typeorm-extensions).
|
|
56
|
+
|
|
57
|
+
## ToDo list
|
|
58
|
+
|
|
59
|
+
- [ ] Add tests for pagination and order extensions
|
|
60
|
+
- [ ] Virtual column decorator and its query-builder methods (`addSelectVirtual`, `orderByVirtual`, `getManyWithVirtual`, `getOneWithVirtual`)
|
|
61
|
+
- [ ] Add `withVirtualColumns` option to `findManyWithTotals` method to use `getManyWithVirtual` instead of `getMany`
|
|
62
|
+
- [ ] Add `isVirtual` option to `OrderParam` to indicate usage of `orderByVirtual` method
|
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import './declarations/get-many-with-totals.declaration';
|
|
2
2
|
import './pagination.extension';
|
|
3
|
-
export type GetManyWithTotalsOptions = {
|
|
4
|
-
disableTotalsCalculation?: boolean;
|
|
5
|
-
loadAll?: boolean;
|
|
6
|
-
};
|
|
7
|
-
export interface ListWithTotals<Entity> {
|
|
8
|
-
list: Entity[];
|
|
9
|
-
totalCount: number | null;
|
|
10
|
-
limit: number | null;
|
|
11
|
-
offset: number | null;
|
|
12
|
-
}
|
|
13
|
-
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
14
|
-
interface SelectQueryBuilder<Entity> {
|
|
15
|
-
getManyWithTotals(paginationFilter: PaginationFilter, options?: GetManyWithTotalsOptions): Promise<ListWithTotals<Entity>>;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,31 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("./declarations/get-many-with-totals.declaration");
|
|
3
4
|
const SelectQueryBuilder_1 = require("typeorm/query-builder/SelectQueryBuilder");
|
|
4
5
|
const pagination_utils_1 = require("../utils/pagination.utils");
|
|
5
6
|
require("./pagination.extension");
|
|
6
|
-
|
|
7
|
+
const prototype_utils_1 = require("../utils/prototype.utils");
|
|
8
|
+
// patching
|
|
9
|
+
const extension = {
|
|
10
|
+
prototype: {
|
|
11
|
+
getManyWithTotals(paginationFilter, options) {
|
|
12
|
+
return getManyWithTotals(this, paginationFilter, options);
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
(0, prototype_utils_1.patchPrototype)(SelectQueryBuilder_1.SelectQueryBuilder, extension);
|
|
17
|
+
// implementation
|
|
18
|
+
async function getManyWithTotals(builder, paginationFilter, options) {
|
|
7
19
|
const { disableTotalsCalculation = false, loadAll = false, ...paginationOptions } = options || {};
|
|
8
20
|
const { limit, offset } = loadAll
|
|
9
21
|
? { limit: null, offset: null }
|
|
10
22
|
: (0, pagination_utils_1.getLimitAndOffset)(paginationFilter);
|
|
11
23
|
const requests = [];
|
|
12
24
|
if (!disableTotalsCalculation) {
|
|
13
|
-
requests[0] =
|
|
25
|
+
requests[0] = await builder.getCount();
|
|
14
26
|
}
|
|
15
27
|
else {
|
|
16
|
-
requests[0] =
|
|
28
|
+
requests[0] = null;
|
|
17
29
|
}
|
|
18
30
|
if (loadAll) {
|
|
19
|
-
requests[1] =
|
|
31
|
+
requests[1] = await builder.getMany();
|
|
20
32
|
}
|
|
21
33
|
else {
|
|
22
|
-
requests[1] =
|
|
34
|
+
requests[1] = await builder
|
|
35
|
+
.applyPaginationFilter(paginationFilter, paginationOptions)
|
|
36
|
+
.getMany();
|
|
23
37
|
}
|
|
24
|
-
const [
|
|
38
|
+
const [total, list] = requests;
|
|
25
39
|
return {
|
|
26
40
|
list,
|
|
27
|
-
|
|
41
|
+
total,
|
|
28
42
|
limit,
|
|
29
43
|
offset,
|
|
30
44
|
};
|
|
31
|
-
}
|
|
45
|
+
}
|
package/dist/extensions/index.js
CHANGED
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./get-many-with-totals.extension"), exports);
|
|
18
18
|
__exportStar(require("./order.extension"), exports);
|
|
19
19
|
__exportStar(require("./pagination.extension"), exports);
|
|
20
|
+
__exportStar(require("./where-is-in.extension"), exports);
|
|
20
21
|
__exportStar(require("./typed"), exports);
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export type ApplyOrderOptions = {
|
|
3
|
-
useDoubleQuotes?: boolean;
|
|
4
|
-
alias?: string;
|
|
5
|
-
alwaysAliasFields?: string[];
|
|
6
|
-
resetPreviousOrder?: boolean;
|
|
7
|
-
};
|
|
8
|
-
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
9
|
-
interface SelectQueryBuilder<Entity> {
|
|
10
|
-
applyOrder<OrderEntity>(orderBy: OrderParam<OrderEntity>, options?: ApplyOrderOptions): SelectQueryBuilder<Entity>;
|
|
11
|
-
applyOrderFilter<OrderEntity>(orderFilter: OrderFilter<OrderEntity>, options?: ApplyOrderOptions): SelectQueryBuilder<Entity>;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export declare const getOrderOption: <OrderEntity>(orderBy: OrderParam<OrderEntity>, defaultAlias: string, options?: ApplyOrderOptions) => OrderType;
|
|
15
|
-
export {};
|
|
1
|
+
import './declarations/order.declaration';
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
+
require("./declarations/order.declaration");
|
|
4
5
|
const SelectQueryBuilder_1 = require("typeorm/query-builder/SelectQueryBuilder");
|
|
5
6
|
const constants_1 = require("../constants");
|
|
6
7
|
const common_utils_1 = require("../utils/common.utils");
|
|
7
8
|
const identifier_utils_1 = require("../utils/identifier.utils");
|
|
9
|
+
const prototype_utils_1 = require("../utils/prototype.utils");
|
|
10
|
+
// patching
|
|
11
|
+
const extension = {
|
|
12
|
+
prototype: {
|
|
13
|
+
applyOrder(orderBy, options) {
|
|
14
|
+
return applyOrder(this, orderBy, options);
|
|
15
|
+
},
|
|
16
|
+
applyOrderFilter(orderFilter, options) {
|
|
17
|
+
return applyOrderFilter(this, orderFilter, options);
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
(0, prototype_utils_1.patchPrototype)(SelectQueryBuilder_1.SelectQueryBuilder, extension);
|
|
22
|
+
// implementation
|
|
8
23
|
const alwaysAliasWhiteList = [
|
|
9
24
|
'id',
|
|
10
25
|
'createdAt',
|
|
@@ -14,29 +29,18 @@ const alwaysAliasWhiteList = [
|
|
|
14
29
|
'deletedAt',
|
|
15
30
|
'deleted_at',
|
|
16
31
|
];
|
|
17
|
-
|
|
18
|
-
const { resetPreviousOrder = false } = options !== null && options !== void 0 ? options : {};
|
|
19
|
-
const orderOption = (0, exports.getOrderOption)(orderBy, this.alias, options);
|
|
20
|
-
const query = resetPreviousOrder ? this.orderBy() : this;
|
|
21
|
-
return query.addOrderBy(orderOption.selector, orderOption.order, orderOption.nulls);
|
|
22
|
-
};
|
|
23
|
-
SelectQueryBuilder_1.SelectQueryBuilder.prototype.applyOrderFilter = function (orderFilter, options) {
|
|
24
|
-
if (!(0, common_utils_1.isNil)(orderFilter === null || orderFilter === void 0 ? void 0 : orderFilter.orderBy)) {
|
|
25
|
-
return orderFilter.orderBy.reduce((acc, order, index) => acc.applyOrder(order, {
|
|
26
|
-
...options,
|
|
27
|
-
resetPreviousOrder: index === 0 ? options === null || options === void 0 ? void 0 : options.resetPreviousOrder : false,
|
|
28
|
-
}), this);
|
|
29
|
-
}
|
|
30
|
-
return this;
|
|
31
|
-
};
|
|
32
|
-
const getOrderOption = (orderBy, defaultAlias, options) => {
|
|
32
|
+
function getOrderOption(orderBy, defaultAlias, options) {
|
|
33
33
|
const { useDoubleQuotes = constants_1.defaultUseDoubleQuotes, alias: customAlias, alwaysAliasFields = alwaysAliasWhiteList, } = options !== null && options !== void 0 ? options : {};
|
|
34
34
|
const { field, direction = constants_1.defaultOrderDirection, nulls: nullsOrder = constants_1.defaultNullsOrder, } = orderBy;
|
|
35
35
|
const alias = customAlias !== null && customAlias !== void 0 ? customAlias : (alwaysAliasFields.includes(field) ? defaultAlias : undefined);
|
|
36
36
|
const identifier = new identifier_utils_1.Identifier(field, alias, useDoubleQuotes);
|
|
37
37
|
const selector = identifier.fieldIdentifier();
|
|
38
|
-
const order = direction
|
|
39
|
-
|
|
38
|
+
const order = typeof direction === 'number'
|
|
39
|
+
? direction === -1
|
|
40
|
+
? 'DESC'
|
|
41
|
+
: 'ASC'
|
|
42
|
+
: direction.toUpperCase();
|
|
43
|
+
const nulls = nullsOrder && /first|last/i.test(nullsOrder)
|
|
40
44
|
? `NULLS ${nullsOrder.toUpperCase()}`
|
|
41
45
|
: undefined;
|
|
42
46
|
return {
|
|
@@ -44,5 +48,19 @@ const getOrderOption = (orderBy, defaultAlias, options) => {
|
|
|
44
48
|
order,
|
|
45
49
|
nulls,
|
|
46
50
|
};
|
|
47
|
-
}
|
|
48
|
-
|
|
51
|
+
}
|
|
52
|
+
function applyOrder(builder, orderBy, options) {
|
|
53
|
+
const { resetPreviousOrder = false } = options !== null && options !== void 0 ? options : {};
|
|
54
|
+
const orderOption = getOrderOption(orderBy, builder.alias, options);
|
|
55
|
+
const query = resetPreviousOrder ? builder.orderBy() : builder;
|
|
56
|
+
return query.addOrderBy(orderOption.selector, orderOption.order, orderOption.nulls);
|
|
57
|
+
}
|
|
58
|
+
function applyOrderFilter(builder, orderFilter, options) {
|
|
59
|
+
if ((orderFilter === null || orderFilter === void 0 ? void 0 : orderFilter.orderBy) && !(0, common_utils_1.isNil)(orderFilter === null || orderFilter === void 0 ? void 0 : orderFilter.orderBy)) {
|
|
60
|
+
return orderFilter.orderBy.reduce((acc, order, index) => acc.applyOrder(order, {
|
|
61
|
+
...options,
|
|
62
|
+
resetPreviousOrder: index === 0 ? options === null || options === void 0 ? void 0 : options.resetPreviousOrder : false,
|
|
63
|
+
}), builder);
|
|
64
|
+
}
|
|
65
|
+
return builder;
|
|
66
|
+
}
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export type ApplyPaginationOptions = {
|
|
3
|
-
useTakeAndSkip?: boolean;
|
|
4
|
-
};
|
|
5
|
-
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
6
|
-
interface SelectQueryBuilder<Entity> {
|
|
7
|
-
applyPaginationFilter(paginationFilter: PaginationFilter, options?: ApplyPaginationOptions): SelectQueryBuilder<Entity>;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export {};
|
|
1
|
+
import './declarations/pagination.declaration';
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
+
require("./declarations/pagination.declaration");
|
|
3
5
|
const SelectQueryBuilder_1 = require("typeorm/query-builder/SelectQueryBuilder");
|
|
4
6
|
const constants_1 = require("../constants");
|
|
5
7
|
const pagination_utils_1 = require("../utils/pagination.utils");
|
|
6
|
-
|
|
8
|
+
const prototype_utils_1 = require("../utils/prototype.utils");
|
|
9
|
+
// patching
|
|
10
|
+
const extension = {
|
|
11
|
+
prototype: {
|
|
12
|
+
applyPaginationFilter(paginationFilter, options) {
|
|
13
|
+
return applyPaginationFilter(this, paginationFilter, options);
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
(0, prototype_utils_1.patchPrototype)(SelectQueryBuilder_1.SelectQueryBuilder, extension);
|
|
18
|
+
// implementation
|
|
19
|
+
function applyPaginationFilter(builder, paginationFilter, options) {
|
|
7
20
|
const { useTakeAndSkip = constants_1.defaultUseTakeAndSkip } = options || {};
|
|
8
21
|
const { limit, offset } = (0, pagination_utils_1.getLimitAndOffset)(paginationFilter);
|
|
9
22
|
if (useTakeAndSkip) {
|
|
10
|
-
return
|
|
23
|
+
return builder.take(limit).skip(offset);
|
|
11
24
|
}
|
|
12
|
-
return
|
|
13
|
-
}
|
|
25
|
+
return builder.limit(limit).offset(offset);
|
|
26
|
+
}
|
|
@@ -3,5 +3,4 @@ export * from './typed-joins/typed-joins.extension';
|
|
|
3
3
|
export * from './typed-order-by/typed-order-by.extension';
|
|
4
4
|
export * from './typed-select/typed-select.extension';
|
|
5
5
|
export * from './typed-where/typed-where.extension';
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './typeorm.types';
|
|
6
|
+
export * from './typed-where/typed-where-is-in.extension';
|
|
@@ -22,6 +22,4 @@ __exportStar(require("./typed-joins/typed-joins.extension"), exports);
|
|
|
22
22
|
__exportStar(require("./typed-order-by/typed-order-by.extension"), exports);
|
|
23
23
|
__exportStar(require("./typed-select/typed-select.extension"), exports);
|
|
24
24
|
__exportStar(require("./typed-where/typed-where.extension"), exports);
|
|
25
|
-
|
|
26
|
-
__exportStar(require("./typeorm-querybuilder.types"), exports);
|
|
27
|
-
__exportStar(require("./typeorm.types"), exports);
|
|
25
|
+
__exportStar(require("./typed-where/typed-where-is-in.extension"), exports);
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ColumnValueType } from '../typeorm.types';
|
|
3
|
-
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
4
|
-
interface SelectQueryBuilder<Entity> {
|
|
5
|
-
/**
|
|
6
|
-
* Sets the distinct on clause for Postgres.
|
|
7
|
-
*/
|
|
8
|
-
distinctOnTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, ...distinctOn: Array<(proxy: Type) => ColumnValueType>): SelectQueryBuilder<Entity>;
|
|
9
|
-
/**
|
|
10
|
-
* Sets the distinct on clause for Postgres.
|
|
11
|
-
*/
|
|
12
|
-
distinctOnTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, distinctOn: (proxy: Type) => Array<ColumnValueType>): SelectQueryBuilder<Entity>;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
1
|
+
import '../../declarations/typed/typed-distinct.declaration';
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("../../declarations/typed/typed-distinct.declaration");
|
|
3
4
|
const typeorm_1 = require("typeorm");
|
|
4
5
|
const proxy_key_utils_1 = require("../../../utils/proxy-key.utils");
|
|
6
|
+
// patching and implementation
|
|
5
7
|
typeorm_1.SelectQueryBuilder.prototype.distinctOnTyped = function (...distinctOn) {
|
|
6
8
|
if (Array.isArray(distinctOn) && distinctOn.length) {
|
|
7
|
-
const keys = distinctOn.map((callback) => (0, proxy_key_utils_1.
|
|
9
|
+
const keys = distinctOn.map((callback) => (0, proxy_key_utils_1.getSqlKeyFromProxyCallback)(callback, this.alias)).flat();
|
|
8
10
|
return this.distinctOn(keys);
|
|
9
11
|
}
|
|
10
12
|
return this;
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { RelationalKeyProxyCallback } from '../typeorm-querybuilder.types';
|
|
3
|
-
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
4
|
-
interface SelectQueryBuilder<Entity> {
|
|
5
|
-
leftJoinTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral): SelectQueryBuilder<Entity>;
|
|
6
|
-
innerJoinTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral): SelectQueryBuilder<Entity>;
|
|
7
|
-
leftJoinAndSelectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral): SelectQueryBuilder<Entity>;
|
|
8
|
-
innerJoinAndSelectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: RelationalKeyProxyCallback<Type>, alias: string, condition?: string, parameters?: ObjectLiteral): SelectQueryBuilder<Entity>;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
import '../../declarations/typed/typed-joins.declaration';
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("../../declarations/typed/typed-joins.declaration");
|
|
3
4
|
const typeorm_1 = require("typeorm");
|
|
4
5
|
const proxy_key_utils_1 = require("../../../utils/proxy-key.utils");
|
|
6
|
+
// patching
|
|
5
7
|
typeorm_1.SelectQueryBuilder.prototype.leftJoinTyped = function (selection, alias, condition, parameters) {
|
|
6
8
|
if (typeof selection === 'function') {
|
|
7
9
|
return addJoin(this, 'leftJoin', selection, alias, condition, parameters);
|
|
@@ -27,6 +29,6 @@ typeorm_1.SelectQueryBuilder.prototype.innerJoinAndSelectTyped = function (selec
|
|
|
27
29
|
return this;
|
|
28
30
|
};
|
|
29
31
|
function addJoin(query, method, selection, alias, condition, parameters) {
|
|
30
|
-
const key = (0, proxy_key_utils_1.
|
|
32
|
+
const key = (0, proxy_key_utils_1.getSqlKeyFromProxyCallback)(selection, query.alias);
|
|
31
33
|
return query[method](key, alias, condition, parameters);
|
|
32
34
|
}
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ColumnValueType } from '../typeorm.types';
|
|
3
|
-
import { KeyHolder } from '../typeorm-querybuilder.types';
|
|
4
|
-
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
5
|
-
interface SelectQueryBuilder<Entity> {
|
|
6
|
-
/**
|
|
7
|
-
* Sets ORDER BY condition in the query builder.
|
|
8
|
-
* If you had previously ORDER BY expression defined,
|
|
9
|
-
* calling this function will override previously set ORDER BY conditions.
|
|
10
|
-
*/
|
|
11
|
-
orderByTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: (proxy: Type) => ColumnValueType | KeyHolder, order?: 'ASC' | 'DESC', nulls?: 'NULLS FIRST' | 'NULLS LAST'): SelectQueryBuilder<Entity>;
|
|
12
|
-
/**
|
|
13
|
-
* Adds ORDER BY condition in the query builder.
|
|
14
|
-
*/
|
|
15
|
-
addOrderByTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: (proxy: Type) => ColumnValueType | KeyHolder, order?: 'ASC' | 'DESC', nulls?: 'NULLS FIRST' | 'NULLS LAST'): SelectQueryBuilder<Entity>;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
1
|
+
import '../../declarations/typed/typed-order-by.declaration';
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("../../declarations/typed/typed-order-by.declaration");
|
|
3
4
|
const typeorm_1 = require("typeorm");
|
|
4
|
-
const typeorm_querybuilder_types_1 = require("../typeorm-querybuilder.types");
|
|
5
5
|
const proxy_key_utils_1 = require("../../../utils/proxy-key.utils");
|
|
6
|
+
// patching and implementation
|
|
6
7
|
typeorm_1.SelectQueryBuilder.prototype.orderByTyped = function (selection, order, nulls) {
|
|
7
|
-
if (selection instanceof
|
|
8
|
+
if (selection instanceof proxy_key_utils_1.KeyHolder) {
|
|
8
9
|
return this.orderBy(selection.toSql(), order, nulls);
|
|
9
10
|
}
|
|
10
11
|
if (typeof selection === 'function') {
|
|
11
|
-
const key = (0, proxy_key_utils_1.
|
|
12
|
+
const key = (0, proxy_key_utils_1.getSqlKeyFromProxyCallback)(selection, this.alias);
|
|
12
13
|
return this.orderBy(key, order, nulls);
|
|
13
14
|
}
|
|
14
15
|
return this;
|
|
15
16
|
};
|
|
16
17
|
typeorm_1.SelectQueryBuilder.prototype.addOrderByTyped = function (selection, order, nulls) {
|
|
17
|
-
if (selection instanceof
|
|
18
|
+
if (selection instanceof proxy_key_utils_1.KeyHolder) {
|
|
18
19
|
return this.addOrderBy(selection.toSql(), order, nulls);
|
|
19
20
|
}
|
|
20
21
|
if (typeof selection === 'function') {
|
|
21
|
-
const key = (0, proxy_key_utils_1.
|
|
22
|
+
const key = (0, proxy_key_utils_1.getSqlKeyFromProxyCallback)(selection, this.alias);
|
|
22
23
|
return this.addOrderBy(key, order, nulls);
|
|
23
24
|
}
|
|
24
25
|
return this;
|
|
@@ -1,33 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { KeyHolder, KeyProxyCallback } from '../typeorm-querybuilder.types';
|
|
3
|
-
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
4
|
-
interface SelectQueryBuilder<Entity> {
|
|
5
|
-
/**
|
|
6
|
-
* Creates SELECT query.
|
|
7
|
-
* Replaces all previous selections if they exist.
|
|
8
|
-
*/
|
|
9
|
-
selectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: KeyProxyCallback<Type>, selectionAliasName?: string): SelectQueryBuilder<Entity>;
|
|
10
|
-
/**
|
|
11
|
-
* Creates SELECT query and selects given data.
|
|
12
|
-
* Replaces all previous selections if they exist.
|
|
13
|
-
*/
|
|
14
|
-
selectTyped(this: SelectQueryBuilder<Entity>, selection: string | KeyHolder, selectionAliasName?: string): SelectQueryBuilder<Entity>;
|
|
15
|
-
/**
|
|
16
|
-
* Creates SELECT query and selects given data.
|
|
17
|
-
* Replaces all previous selections if they exist.
|
|
18
|
-
*/
|
|
19
|
-
selectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: string[] | KeyHolder[] | Array<KeyProxyCallback<Type>>): SelectQueryBuilder<Entity>;
|
|
20
|
-
/**
|
|
21
|
-
* Adds new selection to the SELECT query.
|
|
22
|
-
*/
|
|
23
|
-
addSelectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: KeyProxyCallback<Type>, selectionAliasName?: string): SelectQueryBuilder<Entity>;
|
|
24
|
-
/**
|
|
25
|
-
* Adds new selection to the SELECT query.
|
|
26
|
-
*/
|
|
27
|
-
addSelectTyped(this: SelectQueryBuilder<Entity>, selection: string | KeyHolder, selectionAliasName?: string): SelectQueryBuilder<Entity>;
|
|
28
|
-
/**
|
|
29
|
-
* Adds new selection to the SELECT query.
|
|
30
|
-
*/
|
|
31
|
-
addSelectTyped<Type extends ObjectLiteral = Entity>(this: SelectQueryBuilder<Entity>, selection: string[] | KeyHolder[] | Array<KeyProxyCallback<Type>>): SelectQueryBuilder<Entity>;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
import '../../declarations/typed/typed-select.declaration';
|
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("../../declarations/typed/typed-select.declaration");
|
|
3
4
|
const typeorm_1 = require("typeorm");
|
|
4
|
-
const typeorm_querybuilder_types_1 = require("../typeorm-querybuilder.types");
|
|
5
5
|
const proxy_key_utils_1 = require("../../../utils/proxy-key.utils");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
7
|
+
// patching
|
|
8
|
+
const extension = {
|
|
9
|
+
prototype: {
|
|
10
|
+
selectTyped(selection, selectionAliasName) {
|
|
11
|
+
return attachSelectMethod(this, 'select', selection, selectionAliasName);
|
|
12
|
+
},
|
|
13
|
+
addSelectTyped(selection, selectionAliasName) {
|
|
14
|
+
return attachSelectMethod(this, 'addSelect', selection, selectionAliasName);
|
|
15
|
+
},
|
|
16
|
+
},
|
|
11
17
|
};
|
|
18
|
+
(0, prototype_utils_1.patchPrototype)(typeorm_1.SelectQueryBuilder, extension);
|
|
19
|
+
// implementation
|
|
12
20
|
const attachSelectMethod = (query, method, selection, selectionAliasName) => {
|
|
13
|
-
if (selection instanceof
|
|
21
|
+
if (selection instanceof proxy_key_utils_1.KeyHolder) {
|
|
14
22
|
return query[method](selection.toSql(), selectionAliasName);
|
|
15
23
|
}
|
|
16
24
|
if (Array.isArray(selection)) {
|
|
17
|
-
const arrayOfKeys = selection.map((
|
|
25
|
+
const arrayOfKeys = selection.map((select) => (0, proxy_key_utils_1.getSqlKeyFromProxyCallback)(select, query.alias));
|
|
18
26
|
return query[method](arrayOfKeys);
|
|
19
27
|
}
|
|
20
28
|
else if (typeof selection === 'function') {
|
|
21
|
-
const keyArrayOrSingleKey = (0, proxy_key_utils_1.
|
|
29
|
+
const keyArrayOrSingleKey = (0, proxy_key_utils_1.getSqlKeyFromProxyCallback)(selection, query.alias);
|
|
22
30
|
if (Array.isArray(keyArrayOrSingleKey)) {
|
|
23
31
|
return query[method](keyArrayOrSingleKey);
|
|
24
32
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("../../declarations/typed/typed-where-is-in.declaration");
|
|
4
|
+
require("../../where-is-in.extension");
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
const proxy_key_utils_1 = require("../../../utils/proxy-key.utils");
|
|
7
|
+
const prototype_utils_1 = require("../../../utils/prototype.utils");
|
|
8
|
+
// patching
|
|
9
|
+
const extension = {
|
|
10
|
+
prototype: {
|
|
11
|
+
whereIsInTyped: function (where, array, options) {
|
|
12
|
+
return attachWhereIsIn(this, 'whereIsIn', where, array, options);
|
|
13
|
+
},
|
|
14
|
+
andWhereIsInTyped: function (where, array, options) {
|
|
15
|
+
return attachWhereIsIn(this, 'andWhereIsIn', where, array, options);
|
|
16
|
+
},
|
|
17
|
+
orWhereIsInTyped: function (where, array, options) {
|
|
18
|
+
return attachWhereIsIn(this, 'orWhereIsIn', where, array, options);
|
|
19
|
+
},
|
|
20
|
+
whereIsNotInTyped: function (where, array, options) {
|
|
21
|
+
return attachWhereIsIn(this, 'whereIsNotIn', where, array, options);
|
|
22
|
+
},
|
|
23
|
+
andWhereIsNotInTyped: function (where, array, options) {
|
|
24
|
+
return attachWhereIsIn(this, 'andWhereIsNotIn', where, array, options);
|
|
25
|
+
},
|
|
26
|
+
orWhereIsNotInTyped: function (where, array, options) {
|
|
27
|
+
return attachWhereIsIn(this, 'orWhereIsNotIn', where, array, options);
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const queryBuilders = [
|
|
32
|
+
typeorm_1.SelectQueryBuilder,
|
|
33
|
+
typeorm_1.UpdateQueryBuilder,
|
|
34
|
+
typeorm_1.DeleteQueryBuilder,
|
|
35
|
+
];
|
|
36
|
+
queryBuilders.forEach((builder) => {
|
|
37
|
+
(0, prototype_utils_1.patchPrototype)(builder, extension);
|
|
38
|
+
});
|
|
39
|
+
// implementation
|
|
40
|
+
function attachWhereIsIn(builder, method, where, array, options) {
|
|
41
|
+
const { useDoubleQuotes } = options || {};
|
|
42
|
+
if (typeof where === 'function') {
|
|
43
|
+
const alias = builder.alias;
|
|
44
|
+
const key = (0, proxy_key_utils_1.getSqlKeyFromProxyCallback)(where, alias, useDoubleQuotes);
|
|
45
|
+
if (Array.isArray(key)) {
|
|
46
|
+
for (const k of key) {
|
|
47
|
+
builder = builder[method](k, array);
|
|
48
|
+
}
|
|
49
|
+
return builder;
|
|
50
|
+
}
|
|
51
|
+
// .andWhere(`"table"."column" IN (:...values)`, { values: ['value'] })
|
|
52
|
+
return builder[method](key, array);
|
|
53
|
+
}
|
|
54
|
+
return builder;
|
|
55
|
+
}
|
|
@@ -1,89 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ColumnValueType } from '../typeorm.types';
|
|
3
|
-
export interface TypedWhereOptions {
|
|
4
|
-
useDoubleQuotes?: boolean;
|
|
5
|
-
}
|
|
6
|
-
declare module 'typeorm/query-builder/WhereExpressionBuilder' {
|
|
7
|
-
interface WhereExpressionBuilder {
|
|
8
|
-
/**
|
|
9
|
-
* Sets WHERE condition in the query builder.
|
|
10
|
-
* If you had previously WHERE expression defined,
|
|
11
|
-
* calling this function will override previously set WHERE conditions.
|
|
12
|
-
* Additionally you can add parameters used in where expression.
|
|
13
|
-
*/
|
|
14
|
-
whereTyped<Type extends ObjectLiteral>(subQuery: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
15
|
-
/**
|
|
16
|
-
* Adds new AND WHERE condition in the query builder.
|
|
17
|
-
* Additionally you can add parameters used in where expression.
|
|
18
|
-
*/
|
|
19
|
-
andWhereTyped<Type extends ObjectLiteral>(subQuery: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
20
|
-
/**
|
|
21
|
-
* Adds new OR WHERE condition in the query builder.
|
|
22
|
-
* Additionally you can add parameters used in where expression.
|
|
23
|
-
*/
|
|
24
|
-
orWhereTyped<Type extends ObjectLiteral>(subQuery: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
declare module 'typeorm/query-builder/SelectQueryBuilder' {
|
|
28
|
-
interface SelectQueryBuilder<Entity> {
|
|
29
|
-
/**
|
|
30
|
-
* Sets WHERE condition in the query builder.
|
|
31
|
-
* If you had previously WHERE expression defined,
|
|
32
|
-
* calling this function will override previously set WHERE conditions.
|
|
33
|
-
* Additionally you can add parameters used in where expression.
|
|
34
|
-
*/
|
|
35
|
-
whereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
36
|
-
/**
|
|
37
|
-
* Adds new AND WHERE condition in the query builder.
|
|
38
|
-
* Additionally you can add parameters used in where expression.
|
|
39
|
-
*/
|
|
40
|
-
andWhereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
41
|
-
/**
|
|
42
|
-
* Adds new OR WHERE condition in the query builder.
|
|
43
|
-
* Additionally you can add parameters used in where expression.
|
|
44
|
-
*/
|
|
45
|
-
orWhereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
declare module 'typeorm/query-builder/UpdateQueryBuilder' {
|
|
49
|
-
interface UpdateQueryBuilder<Entity> {
|
|
50
|
-
/**
|
|
51
|
-
* Sets WHERE condition in the query builder.
|
|
52
|
-
* If you had previously WHERE expression defined,
|
|
53
|
-
* calling this function will override previously set WHERE conditions.
|
|
54
|
-
* Additionally you can add parameters used in where expression.
|
|
55
|
-
*/
|
|
56
|
-
whereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
57
|
-
/**
|
|
58
|
-
* Adds new AND WHERE condition in the query builder.
|
|
59
|
-
* Additionally you can add parameters used in where expression.
|
|
60
|
-
*/
|
|
61
|
-
andWhereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
62
|
-
/**
|
|
63
|
-
* Adds new OR WHERE condition in the query builder.
|
|
64
|
-
* Additionally you can add parameters used in where expression.
|
|
65
|
-
*/
|
|
66
|
-
orWhereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
declare module 'typeorm/query-builder/DeleteQueryBuilder' {
|
|
70
|
-
interface DeleteQueryBuilder<Entity> {
|
|
71
|
-
/**
|
|
72
|
-
* Sets WHERE condition in the query builder.
|
|
73
|
-
* If you had previously WHERE expression defined,
|
|
74
|
-
* calling this function will override previously set WHERE conditions.
|
|
75
|
-
* Additionally you can add parameters used in where expression.
|
|
76
|
-
*/
|
|
77
|
-
whereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
78
|
-
/**
|
|
79
|
-
* Adds new AND WHERE condition in the query builder.
|
|
80
|
-
* Additionally you can add parameters used in where expression.
|
|
81
|
-
*/
|
|
82
|
-
andWhereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
83
|
-
/**
|
|
84
|
-
* Adds new OR WHERE condition in the query builder.
|
|
85
|
-
* Additionally you can add parameters used in where expression.
|
|
86
|
-
*/
|
|
87
|
-
orWhereTyped<Type extends ObjectLiteral = Entity>(where: (proxy: Type) => ColumnValueType, conditions: string, parameters?: ObjectLiteral, options?: TypedWhereOptions): this;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
1
|
+
import '../../declarations/typed/typed-where.declaration';
|