@ptc-org/nestjs-query-sequelize 1.0.0-alpha.1 → 2.0.0-alpha.1
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 +8 -7
- package/package.json +4 -4
- package/src/index.d.ts +2 -0
- package/src/index.js +3 -3
- package/src/index.js.map +1 -0
- package/src/module.d.ts +5 -0
- package/src/module.js +19 -0
- package/src/module.js.map +1 -0
- package/src/providers.d.ts +3 -0
- package/src/providers.js +21 -0
- package/src/providers.js.map +1 -0
- package/src/query/aggregate.builder.d.ts +19 -0
- package/src/query/aggregate.builder.js +87 -0
- package/src/query/aggregate.builder.js.map +1 -0
- package/src/query/filter-query.builder.d.ts +96 -0
- package/src/query/filter-query.builder.js +203 -0
- package/src/query/filter-query.builder.js.map +1 -0
- package/src/query/index.d.ts +4 -0
- package/src/query/index.js +8 -0
- package/src/query/index.js.map +1 -0
- package/src/query/sql-comparison.builder.d.ts +26 -0
- package/src/query/sql-comparison.builder.js +74 -0
- package/src/query/sql-comparison.builder.js.map +1 -0
- package/src/query/where.builder.d.ts +24 -0
- package/src/query/where.builder.js +81 -0
- package/src/query/where.builder.js.map +1 -0
- package/src/services/index.d.ts +1 -0
- package/src/services/index.js +5 -0
- package/src/services/index.js.map +1 -0
- package/src/services/relation-query.service.d.ts +119 -0
- package/src/services/relation-query.service.js +234 -0
- package/src/services/relation-query.service.js.map +1 -0
- package/src/services/sequelize-query.service.d.ts +147 -0
- package/src/services/sequelize-query.service.js +239 -0
- package/src/services/sequelize-query.service.js.map +1 -0
- package/CHANGELOG.md +0 -426
package/README.md
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<a href="https://
|
|
2
|
+
<a href="https://tripss.github.io/nestjs-query" target="blank"><img src="https://tripss.github.io/nestjs-query/img/logo.svg" width="120" alt="Nestjs-query Logo" /></a>
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.org/package/@ptc-org/nestjs-query-sequelize)
|
|
6
6
|
[](https://github.com/tripss/nestjs-query/actions?query=workflow%3ATest+and+branch%3Amaster+)
|
|
7
|
-
[](https://coveralls.io/github/tripss/nestjs-query?branch=master)
|
|
8
|
+
[](https://snyk.io/test/github/tripss/nestjs-query?targetFile=packages/query-sequelize/package.json)
|
|
9
9
|
|
|
10
10
|
# `@ptc-org/nestjs-query-sequelize`
|
|
11
11
|
|
|
12
|
-
The `query-sequelize` package that provides an implementation of `@ptc-org/nestjs-query-core` `QueryService`, built on
|
|
12
|
+
The `query-sequelize` package that provides an implementation of `@ptc-org/nestjs-query-core` `QueryService`, built on
|
|
13
|
+
top of of [nestjs](https://nestjs.com/) and [sequelize](https://sequelize.org/).
|
|
13
14
|
|
|
14
15
|
## Installation
|
|
15
16
|
|
|
16
|
-
[Install Guide](https://
|
|
17
|
+
[Install Guide](https://tripss.github.io/nestjs-query/docs/introduction/install)
|
|
17
18
|
|
|
18
19
|
## Getting Started
|
|
19
20
|
|
|
20
|
-
The get started with the `@ptc-org/nestjs-query-sequelize` package checkout
|
|
21
|
-
|
|
21
|
+
The get started with the `@ptc-org/nestjs-query-sequelize` package checkout
|
|
22
|
+
the [Getting Started](https://tripss.github.io/nestjs-query/docs/sequelize/getting-started) docs.
|
|
22
23
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ptc-org/nestjs-query-sequelize",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
4
|
"description": "Sequelize adapter for @ptc-org/nestjs-query-core",
|
|
5
5
|
"author": "doug-martin <doug@dougamartin.com>",
|
|
6
6
|
"homepage": "https://github.com/tripss/nestjs-query#readme",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"test": "__tests__"
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
|
-
"
|
|
15
|
+
"src/**"
|
|
16
16
|
],
|
|
17
17
|
"publishConfig": {
|
|
18
18
|
"access": "public"
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"camel-case": "^4.1.2",
|
|
22
22
|
"lodash.pick": "4.4.0",
|
|
23
|
-
"tslib": "^2.
|
|
23
|
+
"tslib": "^2.4.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"@nestjs/common": "^8.0.4",
|
|
27
27
|
"@nestjs/sequelize": "^8.0.0",
|
|
28
28
|
"sequelize": "^6.5.0",
|
|
29
29
|
"sequelize-typescript": "^1.1.0 || ^2.0.0",
|
|
30
|
-
"@ptc-org/nestjs-query-core": "
|
|
30
|
+
"@ptc-org/nestjs-query-core": "2.0.0-alpha.1",
|
|
31
31
|
"reflect-metadata": "^0.1.13"
|
|
32
32
|
},
|
|
33
33
|
"repository": {
|
package/src/index.d.ts
ADDED
package/src/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var services_1 = require("./services");
|
|
5
|
-
Object.defineProperty(exports, "SequelizeQueryService", { enumerable: true, get: function () { return services_1.SequelizeQueryService; } });
|
|
3
|
+
exports.SequelizeQueryService = exports.NestjsQuerySequelizeModule = void 0;
|
|
6
4
|
var module_1 = require("./module");
|
|
7
5
|
Object.defineProperty(exports, "NestjsQuerySequelizeModule", { enumerable: true, get: function () { return module_1.NestjsQuerySequelizeModule; } });
|
|
6
|
+
var services_1 = require("./services");
|
|
7
|
+
Object.defineProperty(exports, "SequelizeQueryService", { enumerable: true, get: function () { return services_1.SequelizeQueryService; } });
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/query-sequelize/src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAqD;AAA5C,oHAAA,0BAA0B,OAAA;AACnC,uCAAkD;AAAzC,iHAAA,qBAAqB,OAAA"}
|
package/src/module.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { ModelCtor, SequelizeOptions } from 'sequelize-typescript';
|
|
3
|
+
export declare class NestjsQuerySequelizeModule {
|
|
4
|
+
static forFeature(entities: ModelCtor[], connection?: SequelizeOptions | string): DynamicModule;
|
|
5
|
+
}
|
package/src/module.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NestjsQuerySequelizeModule = void 0;
|
|
4
|
+
const sequelize_1 = require("@nestjs/sequelize");
|
|
5
|
+
const providers_1 = require("./providers");
|
|
6
|
+
class NestjsQuerySequelizeModule {
|
|
7
|
+
static forFeature(entities, connection) {
|
|
8
|
+
const queryServiceProviders = (0, providers_1.createSequelizeQueryServiceProviders)(entities, connection);
|
|
9
|
+
const nestjsSequelize = sequelize_1.SequelizeModule.forFeature(entities);
|
|
10
|
+
return {
|
|
11
|
+
module: NestjsQuerySequelizeModule,
|
|
12
|
+
imports: [nestjsSequelize],
|
|
13
|
+
providers: [...queryServiceProviders],
|
|
14
|
+
exports: [...queryServiceProviders, nestjsSequelize]
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.NestjsQuerySequelizeModule = NestjsQuerySequelizeModule;
|
|
19
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../../packages/query-sequelize/src/module.ts"],"names":[],"mappings":";;;AACA,iDAAmD;AAGnD,2CAAkE;AAElE,MAAa,0BAA0B;IACrC,MAAM,CAAC,UAAU,CAAC,QAAqB,EAAE,UAAsC;QAC7E,MAAM,qBAAqB,GAAG,IAAA,gDAAoC,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;QACxF,MAAM,eAAe,GAAG,2BAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;QAC5D,OAAO;YACL,MAAM,EAAE,0BAA0B;YAClC,OAAO,EAAE,CAAC,eAAe,CAAC;YAC1B,SAAS,EAAE,CAAC,GAAG,qBAAqB,CAAC;YACrC,OAAO,EAAE,CAAC,GAAG,qBAAqB,EAAE,eAAe,CAAC;SACrD,CAAA;IACH,CAAC;CACF;AAXD,gEAWC"}
|
package/src/providers.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSequelizeQueryServiceProviders = void 0;
|
|
4
|
+
const sequelize_1 = require("@nestjs/sequelize");
|
|
5
|
+
const nestjs_query_core_1 = require("@ptc-org/nestjs-query-core");
|
|
6
|
+
const services_1 = require("./services");
|
|
7
|
+
function createSequelizeQueryServiceProvider(EntityClass, connection) {
|
|
8
|
+
return {
|
|
9
|
+
provide: (0, nestjs_query_core_1.getQueryServiceToken)(EntityClass),
|
|
10
|
+
useFactory(entity) {
|
|
11
|
+
(0, nestjs_query_core_1.AssemblerSerializer)((instance) => instance.get({ plain: true }))(entity);
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
13
|
+
(0, nestjs_query_core_1.AssemblerDeserializer)((obj) => entity.build(obj))(entity);
|
|
14
|
+
return new services_1.SequelizeQueryService(entity);
|
|
15
|
+
},
|
|
16
|
+
inject: [(0, sequelize_1.getModelToken)(EntityClass, connection)]
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const createSequelizeQueryServiceProviders = (entities, connection) => entities.map((entity) => createSequelizeQueryServiceProvider(entity, connection));
|
|
20
|
+
exports.createSequelizeQueryServiceProviders = createSequelizeQueryServiceProviders;
|
|
21
|
+
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../../../../packages/query-sequelize/src/providers.ts"],"names":[],"mappings":";;;AACA,iDAAiD;AACjD,kEAA6G;AAI7G,yCAAkD;AAElD,SAAS,mCAAmC,CAC1C,WAA8B,EAC9B,UAAsC;IAEtC,OAAO;QACL,OAAO,EAAE,IAAA,wCAAoB,EAAC,WAAW,CAAC;QAC1C,UAAU,CAAC,MAAyB;YAClC,IAAA,uCAAmB,EAAS,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAW,CAAC,CAAC,MAAM,CAAC,CAAA;YAC1F,wDAAwD;YACxD,IAAA,yCAAqB,EAAS,CAAC,GAAgC,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;YAC9F,OAAO,IAAI,gCAAqB,CAAC,MAAM,CAAC,CAAA;QAC1C,CAAC;QACD,MAAM,EAAE,CAAC,IAAA,yBAAa,EAAC,WAAW,EAAE,UAAU,CAAC,CAAC;KACjD,CAAA;AACH,CAAC;AAEM,MAAM,oCAAoC,GAAG,CAClD,QAAqB,EACrB,UAAsC,EACnB,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,mCAAmC,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAA;AAH5F,QAAA,oCAAoC,wCAGwD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AggregateQuery, AggregateResponse } from '@ptc-org/nestjs-query-core';
|
|
2
|
+
import { Projectable } from 'sequelize';
|
|
3
|
+
import { Model, ModelCtor } from 'sequelize-typescript';
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
* Builds a WHERE clause from a Filter.
|
|
7
|
+
*/
|
|
8
|
+
export declare class AggregateBuilder<Entity extends Model<Entity, Partial<Entity>>> {
|
|
9
|
+
readonly model: ModelCtor<Entity>;
|
|
10
|
+
static convertToAggregateResponse<Entity>(rawAggregates: Record<string, unknown>[]): AggregateResponse<Entity>[];
|
|
11
|
+
constructor(model: ModelCtor<Entity>);
|
|
12
|
+
/**
|
|
13
|
+
* Builds a aggregate SELECT clause from a aggregate.
|
|
14
|
+
* @param aggregate - the aggregates to select.
|
|
15
|
+
*/
|
|
16
|
+
build(aggregate: AggregateQuery<Entity>): Projectable;
|
|
17
|
+
private createAggSelect;
|
|
18
|
+
private createGroupBySelect;
|
|
19
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AggregateBuilder = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const camel_case_1 = require("camel-case");
|
|
7
|
+
const sequelize_1 = (0, tslib_1.__importDefault)(require("sequelize"));
|
|
8
|
+
var AggregateFuncs;
|
|
9
|
+
(function (AggregateFuncs) {
|
|
10
|
+
AggregateFuncs["AVG"] = "AVG";
|
|
11
|
+
AggregateFuncs["SUM"] = "SUM";
|
|
12
|
+
AggregateFuncs["COUNT"] = "COUNT";
|
|
13
|
+
AggregateFuncs["MAX"] = "MAX";
|
|
14
|
+
AggregateFuncs["MIN"] = "MIN";
|
|
15
|
+
})(AggregateFuncs || (AggregateFuncs = {}));
|
|
16
|
+
const AGG_REGEXP = /(AVG|SUM|COUNT|MAX|MIN|GROUP_BY)_(.*)/;
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
* Builds a WHERE clause from a Filter.
|
|
20
|
+
*/
|
|
21
|
+
class AggregateBuilder {
|
|
22
|
+
constructor(model) {
|
|
23
|
+
this.model = model;
|
|
24
|
+
}
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
26
|
+
static convertToAggregateResponse(rawAggregates) {
|
|
27
|
+
return rawAggregates.map((aggregate) => {
|
|
28
|
+
return Object.keys(aggregate).reduce((agg, resultField) => {
|
|
29
|
+
const matchResult = AGG_REGEXP.exec(resultField);
|
|
30
|
+
if (!matchResult) {
|
|
31
|
+
throw new Error('Unknown aggregate column encountered.');
|
|
32
|
+
}
|
|
33
|
+
const [matchedFunc, matchedFieldName] = matchResult.slice(1);
|
|
34
|
+
const aggResponseKey = (0, camel_case_1.camelCase)(matchedFunc.toLowerCase());
|
|
35
|
+
const fieldName = matchedFieldName;
|
|
36
|
+
const aggResult = agg[aggResponseKey] || {};
|
|
37
|
+
return {
|
|
38
|
+
...agg,
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
40
|
+
[aggResponseKey]: { ...aggResult, [fieldName]: aggregate[resultField] }
|
|
41
|
+
};
|
|
42
|
+
}, {});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Builds a aggregate SELECT clause from a aggregate.
|
|
47
|
+
* @param aggregate - the aggregates to select.
|
|
48
|
+
*/
|
|
49
|
+
build(aggregate) {
|
|
50
|
+
const selects = [
|
|
51
|
+
...this.createGroupBySelect(aggregate.groupBy),
|
|
52
|
+
...this.createAggSelect(AggregateFuncs.COUNT, aggregate.count),
|
|
53
|
+
...this.createAggSelect(AggregateFuncs.SUM, aggregate.sum),
|
|
54
|
+
...this.createAggSelect(AggregateFuncs.AVG, aggregate.avg),
|
|
55
|
+
...this.createAggSelect(AggregateFuncs.MAX, aggregate.max),
|
|
56
|
+
...this.createAggSelect(AggregateFuncs.MIN, aggregate.min)
|
|
57
|
+
];
|
|
58
|
+
if (!selects.length) {
|
|
59
|
+
throw new common_1.BadRequestException('No aggregate fields found.');
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
attributes: selects
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
createAggSelect(func, fields) {
|
|
66
|
+
if (!fields) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
return fields.map((field) => {
|
|
70
|
+
const aggAlias = `${func}_${field}`;
|
|
71
|
+
const colName = this.model.rawAttributes[field].field;
|
|
72
|
+
const fn = sequelize_1.default.fn(func, sequelize_1.default.col(colName || field));
|
|
73
|
+
return [fn, aggAlias];
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
createGroupBySelect(fields) {
|
|
77
|
+
if (!fields) {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
return fields.map((field) => {
|
|
81
|
+
const colName = this.model.rawAttributes[field].field;
|
|
82
|
+
return [sequelize_1.default.col(colName || field), `GROUP_BY_${field}`];
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.AggregateBuilder = AggregateBuilder;
|
|
87
|
+
//# sourceMappingURL=aggregate.builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregate.builder.js","sourceRoot":"","sources":["../../../../../packages/query-sequelize/src/query/aggregate.builder.ts"],"names":[],"mappings":";;;;AAAA,2CAAoD;AAEpD,2CAAsC;AACtC,uEAAkD;AAGlD,IAAK,cAMJ;AAND,WAAK,cAAc;IACjB,6BAAW,CAAA;IACX,6BAAW,CAAA;IACX,iCAAe,CAAA;IACf,6BAAW,CAAA;IACX,6BAAW,CAAA;AACb,CAAC,EANI,cAAc,KAAd,cAAc,QAMlB;AAED,MAAM,UAAU,GAAG,uCAAuC,CAAA;AAE1D;;;GAGG;AACH,MAAa,gBAAgB;IAsB3B,YAAqB,KAAwB;QAAxB,UAAK,GAAL,KAAK,CAAmB;IAAG,CAAC;IArBjD,wDAAwD;IACxD,MAAM,CAAC,0BAA0B,CAAS,aAAwC;QAChF,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;YACrC,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,WAAmB,EAAE,EAAE;gBAChE,MAAM,WAAW,GAAG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,CAAC,OAAO,CAAC,MAAM,EAAE;YACnB,MAAM,IAAI,4BAAmB,CAAC,4BAA4B,CAAC,CAAA;SAC5D;QACD,OAAO;YACL,UAAU,EAAE,OAAO;SACpB,CAAA;IACH,CAAC;IAEO,eAAe,CAAC,IAAoB,EAAE,MAAyB;QACrE,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,EAAE,CAAA;SACV;QACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAC1B,MAAM,QAAQ,GAAG,GAAG,IAAI,IAAI,KAAe,EAAE,CAAA;YAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,KAAe,CAAC,CAAC,KAAK,CAAA;YAC/D,MAAM,EAAE,GAAG,mBAAS,CAAC,EAAE,CAAC,IAAI,EAAE,mBAAS,CAAC,GAAG,CAAC,OAAO,IAAK,KAAgB,CAAC,CAAC,CAAA;YAC1E,OAAO,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;QACvB,CAAC,CAAC,CAAA;IACJ,CAAC;IAEO,mBAAmB,CAAC,MAAyB;QACnD,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,EAAE,CAAA;SACV;QACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAC1B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,KAAe,CAAC,CAAC,KAAK,CAAA;YAC/D,OAAO,CAAC,mBAAS,CAAC,GAAG,CAAC,OAAO,IAAK,KAAgB,CAAC,EAAE,YAAY,KAAe,EAAE,CAAC,CAAA;QACrF,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAlED,4CAkEC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { AggregateQuery, Filter, Paging, Query, SortField } from '@ptc-org/nestjs-query-core';
|
|
2
|
+
import { CountOptions, DestroyOptions, Filterable, FindOptions, GroupOption, Order, UpdateOptions } from 'sequelize';
|
|
3
|
+
import { Model, ModelCtor } from 'sequelize-typescript';
|
|
4
|
+
import { AggregateBuilder } from './aggregate.builder';
|
|
5
|
+
import { WhereBuilder } from './where.builder';
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*
|
|
9
|
+
* Interface that for `sequelize` query builders that are sortable.
|
|
10
|
+
*/
|
|
11
|
+
interface Sortable {
|
|
12
|
+
order?: Order;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*
|
|
17
|
+
* Interface for `sequelize` query builders that are pageable.
|
|
18
|
+
*/
|
|
19
|
+
interface Pageable {
|
|
20
|
+
limit?: number;
|
|
21
|
+
offset?: number;
|
|
22
|
+
}
|
|
23
|
+
interface Groupable {
|
|
24
|
+
group?: GroupOption;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*
|
|
29
|
+
* Class that will convert a Query into a `sequelize` Query Builder.
|
|
30
|
+
*/
|
|
31
|
+
export declare class FilterQueryBuilder<Entity extends Model<Entity, Partial<Entity>>> {
|
|
32
|
+
readonly model: ModelCtor<Entity>;
|
|
33
|
+
readonly whereBuilder: WhereBuilder<Entity>;
|
|
34
|
+
readonly aggregateBuilder: AggregateBuilder<Entity>;
|
|
35
|
+
constructor(model: ModelCtor<Entity>, whereBuilder?: WhereBuilder<Entity>, aggregateBuilder?: AggregateBuilder<Entity>);
|
|
36
|
+
/**
|
|
37
|
+
* Create a `sequelize` SelectQueryBuilder with `WHERE`, `ORDER BY` and `LIMIT/OFFSET` clauses.
|
|
38
|
+
*
|
|
39
|
+
* @param query - the query to apply.
|
|
40
|
+
*/
|
|
41
|
+
findOptions(query: Query<Entity>): FindOptions;
|
|
42
|
+
/**
|
|
43
|
+
* Create a `sequelize` SelectQueryBuilder with `WHERE`, `ORDER BY` and `LIMIT/OFFSET` clauses.
|
|
44
|
+
*
|
|
45
|
+
* @param pk - The primary key(s) of records to find.
|
|
46
|
+
* @param query - the query to apply.
|
|
47
|
+
*/
|
|
48
|
+
findByIdOptions(pk: string | number | (string | number)[], query: Query<Entity>): FindOptions;
|
|
49
|
+
/**
|
|
50
|
+
* Create a `sequelize` SelectQueryBuilder with `WHERE`, `ORDER BY` and `LIMIT/OFFSET` clauses.
|
|
51
|
+
*
|
|
52
|
+
* @param query - the query to apply.
|
|
53
|
+
* @param aggregate - the aggregate query
|
|
54
|
+
*/
|
|
55
|
+
aggregateOptions(query: Query<Entity>, aggregate: AggregateQuery<Entity>): FindOptions;
|
|
56
|
+
relationAggregateOptions(query: Query<Entity>, aggregate: AggregateQuery<Entity>): FindOptions;
|
|
57
|
+
countOptions(query: Query<Entity>): CountOptions<Entity>;
|
|
58
|
+
/**
|
|
59
|
+
* Create a `sequelize` DeleteQueryBuilder with a WHERE clause.
|
|
60
|
+
*
|
|
61
|
+
* @param query - the query to apply.
|
|
62
|
+
*/
|
|
63
|
+
destroyOptions(query: Query<Entity>): DestroyOptions;
|
|
64
|
+
/**
|
|
65
|
+
* Create a `sequelize` UpdateQueryBuilder with `WHERE` and `ORDER BY` clauses
|
|
66
|
+
*
|
|
67
|
+
* @param query - the query to apply.
|
|
68
|
+
*/
|
|
69
|
+
updateOptions(query: Query<Entity>): UpdateOptions<Entity['_attributes']>;
|
|
70
|
+
/**
|
|
71
|
+
* Applies paging to a Pageable `sequelize` query builder
|
|
72
|
+
* @param qb - the `sequelize` QueryBuilder
|
|
73
|
+
* @param paging - the Paging options.
|
|
74
|
+
*/
|
|
75
|
+
applyPaging<P extends Pageable>(qb: P, paging?: Paging): P;
|
|
76
|
+
/**
|
|
77
|
+
* Applies the filter from a Query to a `sequelize` QueryBuilder.
|
|
78
|
+
*
|
|
79
|
+
* @param filterable - the `sequelize` QueryBuilder.
|
|
80
|
+
* @param filter - the filter.
|
|
81
|
+
*/
|
|
82
|
+
applyFilter<Where extends Filterable>(filterable: Where, filter?: Filter<Entity>): Where;
|
|
83
|
+
/**
|
|
84
|
+
* Applies the ORDER BY clause to a `sequelize` QueryBuilder.
|
|
85
|
+
* @param qb - the `sequelize` QueryBuilder.
|
|
86
|
+
* @param sorts - an array of SortFields to create the ORDER BY clause.
|
|
87
|
+
*/
|
|
88
|
+
applySorting<T extends Sortable>(qb: T, sorts?: SortField<Entity>[]): T;
|
|
89
|
+
private applyAggregate;
|
|
90
|
+
applyGroupBy<T extends Groupable>(qb: T, groupBy?: (keyof Entity)[]): T;
|
|
91
|
+
applyAggregateSorting<T extends Sortable>(qb: T, groupBy?: (keyof Entity)[]): T;
|
|
92
|
+
private applyAssociationIncludes;
|
|
93
|
+
private getReferencedRelations;
|
|
94
|
+
private get relationNames();
|
|
95
|
+
}
|
|
96
|
+
export {};
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FilterQueryBuilder = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const nestjs_query_core_1 = require("@ptc-org/nestjs-query-core");
|
|
6
|
+
const sequelize_1 = (0, tslib_1.__importDefault)(require("sequelize"));
|
|
7
|
+
const aggregate_builder_1 = require("./aggregate.builder");
|
|
8
|
+
const where_builder_1 = require("./where.builder");
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*
|
|
12
|
+
* Class that will convert a Query into a `sequelize` Query Builder.
|
|
13
|
+
*/
|
|
14
|
+
class FilterQueryBuilder {
|
|
15
|
+
constructor(model, whereBuilder = new where_builder_1.WhereBuilder(), aggregateBuilder = new aggregate_builder_1.AggregateBuilder(model)) {
|
|
16
|
+
this.model = model;
|
|
17
|
+
this.whereBuilder = whereBuilder;
|
|
18
|
+
this.aggregateBuilder = aggregateBuilder;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a `sequelize` SelectQueryBuilder with `WHERE`, `ORDER BY` and `LIMIT/OFFSET` clauses.
|
|
22
|
+
*
|
|
23
|
+
* @param query - the query to apply.
|
|
24
|
+
*/
|
|
25
|
+
findOptions(query) {
|
|
26
|
+
let opts = this.applyAssociationIncludes({ subQuery: false }, query.filter);
|
|
27
|
+
opts = this.applyFilter(opts, query.filter);
|
|
28
|
+
opts = this.applySorting(opts, query.sorting);
|
|
29
|
+
opts = this.applyPaging(opts, query.paging);
|
|
30
|
+
return opts;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a `sequelize` SelectQueryBuilder with `WHERE`, `ORDER BY` and `LIMIT/OFFSET` clauses.
|
|
34
|
+
*
|
|
35
|
+
* @param pk - The primary key(s) of records to find.
|
|
36
|
+
* @param query - the query to apply.
|
|
37
|
+
*/
|
|
38
|
+
findByIdOptions(pk, query) {
|
|
39
|
+
let opts = this.applyAssociationIncludes({ subQuery: false }, query.filter);
|
|
40
|
+
opts = this.applyFilter(opts, {
|
|
41
|
+
...(query.filter ?? {}),
|
|
42
|
+
[this.model.primaryKeyAttribute]: { [Array.isArray(pk) ? 'in' : 'eq']: pk }
|
|
43
|
+
});
|
|
44
|
+
opts = this.applySorting(opts, query.sorting);
|
|
45
|
+
opts = this.applyPaging(opts, query.paging);
|
|
46
|
+
return opts;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create a `sequelize` SelectQueryBuilder with `WHERE`, `ORDER BY` and `LIMIT/OFFSET` clauses.
|
|
50
|
+
*
|
|
51
|
+
* @param query - the query to apply.
|
|
52
|
+
* @param aggregate - the aggregate query
|
|
53
|
+
*/
|
|
54
|
+
aggregateOptions(query, aggregate) {
|
|
55
|
+
let opts = { raw: true };
|
|
56
|
+
opts = this.applyAggregate(opts, aggregate);
|
|
57
|
+
opts = this.applyFilter(opts, query.filter);
|
|
58
|
+
opts = this.applyAggregateSorting(opts, aggregate.groupBy);
|
|
59
|
+
opts = this.applyGroupBy(opts, aggregate.groupBy);
|
|
60
|
+
return opts;
|
|
61
|
+
}
|
|
62
|
+
relationAggregateOptions(query, aggregate) {
|
|
63
|
+
// joinTableAttributes is used by many-to-many relations and must be empty.
|
|
64
|
+
let opts = { joinTableAttributes: [], raw: true };
|
|
65
|
+
opts = this.applyAggregate(opts, aggregate);
|
|
66
|
+
opts = this.applyFilter(opts, query.filter);
|
|
67
|
+
opts = this.applyAggregateSorting(opts, aggregate.groupBy);
|
|
68
|
+
opts = this.applyGroupBy(opts, aggregate.groupBy);
|
|
69
|
+
return opts;
|
|
70
|
+
}
|
|
71
|
+
countOptions(query) {
|
|
72
|
+
let opts = this.applyAssociationIncludes({}, query.filter);
|
|
73
|
+
opts.distinct = true;
|
|
74
|
+
opts = this.applyFilter(opts, query.filter);
|
|
75
|
+
return opts;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create a `sequelize` DeleteQueryBuilder with a WHERE clause.
|
|
79
|
+
*
|
|
80
|
+
* @param query - the query to apply.
|
|
81
|
+
*/
|
|
82
|
+
destroyOptions(query) {
|
|
83
|
+
let opts = {};
|
|
84
|
+
opts = this.applyFilter(opts, query.filter);
|
|
85
|
+
opts = this.applyPaging(opts, query.paging);
|
|
86
|
+
return opts;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create a `sequelize` UpdateQueryBuilder with `WHERE` and `ORDER BY` clauses
|
|
90
|
+
*
|
|
91
|
+
* @param query - the query to apply.
|
|
92
|
+
*/
|
|
93
|
+
updateOptions(query) {
|
|
94
|
+
let opts = { where: {} };
|
|
95
|
+
opts = this.applyFilter(opts, query.filter);
|
|
96
|
+
opts = this.applyPaging(opts, query.paging);
|
|
97
|
+
return opts;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Applies paging to a Pageable `sequelize` query builder
|
|
101
|
+
* @param qb - the `sequelize` QueryBuilder
|
|
102
|
+
* @param paging - the Paging options.
|
|
103
|
+
*/
|
|
104
|
+
applyPaging(qb, paging) {
|
|
105
|
+
if (!paging) {
|
|
106
|
+
return qb;
|
|
107
|
+
}
|
|
108
|
+
if (paging.limit !== undefined) {
|
|
109
|
+
// eslint-disable-next-line no-param-reassign
|
|
110
|
+
qb.limit = paging.limit;
|
|
111
|
+
}
|
|
112
|
+
if (paging.offset !== undefined) {
|
|
113
|
+
// eslint-disable-next-line no-param-reassign
|
|
114
|
+
qb.offset = paging.offset;
|
|
115
|
+
}
|
|
116
|
+
return qb;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Applies the filter from a Query to a `sequelize` QueryBuilder.
|
|
120
|
+
*
|
|
121
|
+
* @param filterable - the `sequelize` QueryBuilder.
|
|
122
|
+
* @param filter - the filter.
|
|
123
|
+
*/
|
|
124
|
+
applyFilter(filterable, filter) {
|
|
125
|
+
if (!filter) {
|
|
126
|
+
return filterable;
|
|
127
|
+
}
|
|
128
|
+
// eslint-disable-next-line no-param-reassign
|
|
129
|
+
filterable.where = this.whereBuilder.build(filter, this.getReferencedRelations(filter));
|
|
130
|
+
return filterable;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Applies the ORDER BY clause to a `sequelize` QueryBuilder.
|
|
134
|
+
* @param qb - the `sequelize` QueryBuilder.
|
|
135
|
+
* @param sorts - an array of SortFields to create the ORDER BY clause.
|
|
136
|
+
*/
|
|
137
|
+
applySorting(qb, sorts) {
|
|
138
|
+
if (!sorts) {
|
|
139
|
+
return qb;
|
|
140
|
+
}
|
|
141
|
+
// eslint-disable-next-line no-param-reassign
|
|
142
|
+
qb.order = sorts.map(({ field, direction, nulls }) => {
|
|
143
|
+
const col = `${field}`;
|
|
144
|
+
const dir = [direction];
|
|
145
|
+
if (nulls) {
|
|
146
|
+
dir.push(nulls);
|
|
147
|
+
}
|
|
148
|
+
return [col, dir.join(' ')];
|
|
149
|
+
});
|
|
150
|
+
return qb;
|
|
151
|
+
}
|
|
152
|
+
applyAggregate(opts, aggregate) {
|
|
153
|
+
// eslint-disable-next-line no-param-reassign
|
|
154
|
+
opts.attributes = this.aggregateBuilder.build(aggregate).attributes;
|
|
155
|
+
return opts;
|
|
156
|
+
}
|
|
157
|
+
applyGroupBy(qb, groupBy) {
|
|
158
|
+
if (!groupBy) {
|
|
159
|
+
return qb;
|
|
160
|
+
}
|
|
161
|
+
// eslint-disable-next-line no-param-reassign
|
|
162
|
+
qb.group = groupBy.map((field) => {
|
|
163
|
+
const colName = this.model.rawAttributes[field].field;
|
|
164
|
+
return sequelize_1.default.col(colName ?? field);
|
|
165
|
+
});
|
|
166
|
+
return qb;
|
|
167
|
+
}
|
|
168
|
+
applyAggregateSorting(qb, groupBy) {
|
|
169
|
+
if (!groupBy) {
|
|
170
|
+
return qb;
|
|
171
|
+
}
|
|
172
|
+
// eslint-disable-next-line no-param-reassign
|
|
173
|
+
qb.order = groupBy.map((field) => {
|
|
174
|
+
const colName = this.model.rawAttributes[field].field;
|
|
175
|
+
const col = sequelize_1.default.col(colName ?? field);
|
|
176
|
+
return [col, 'ASC'];
|
|
177
|
+
});
|
|
178
|
+
return qb;
|
|
179
|
+
}
|
|
180
|
+
applyAssociationIncludes(findOpts, filter) {
|
|
181
|
+
if (!filter) {
|
|
182
|
+
return findOpts;
|
|
183
|
+
}
|
|
184
|
+
const referencedRelations = this.getReferencedRelations(filter);
|
|
185
|
+
return [...referencedRelations.values()].reduce((find, association) => {
|
|
186
|
+
const { include = [] } = find;
|
|
187
|
+
// eslint-disable-next-line no-param-reassign
|
|
188
|
+
find.include = [...(Array.isArray(include) ? include : [include]), { association, attributes: [] }];
|
|
189
|
+
return find;
|
|
190
|
+
}, findOpts);
|
|
191
|
+
}
|
|
192
|
+
getReferencedRelations(filter) {
|
|
193
|
+
const { relationNames } = this;
|
|
194
|
+
const referencedFields = (0, nestjs_query_core_1.getFilterFields)(filter);
|
|
195
|
+
const referencedRelations = referencedFields.filter((f) => relationNames.includes(f));
|
|
196
|
+
return referencedRelations.reduce((map, r) => map.set(r, this.model.associations[r]), new Map());
|
|
197
|
+
}
|
|
198
|
+
get relationNames() {
|
|
199
|
+
return Object.keys(this.model.associations || {});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.FilterQueryBuilder = FilterQueryBuilder;
|
|
203
|
+
//# sourceMappingURL=filter-query.builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-query.builder.js","sourceRoot":"","sources":["../../../../../packages/query-sequelize/src/query/filter-query.builder.ts"],"names":[],"mappings":";;;;AAAA,kEAA8G;AAC9G,uEAWkB;AAGlB,2DAAsD;AACtD,mDAA8C;AAyB9C;;;;GAIG;AACH,MAAa,kBAAkB;IAC7B,YACW,KAAwB,EACxB,eAAqC,IAAI,4BAAY,EAAU,EAC/D,mBAA6C,IAAI,oCAAgB,CAAS,KAAK,CAAC;QAFhF,UAAK,GAAL,KAAK,CAAmB;QACxB,iBAAY,GAAZ,YAAY,CAAmD;QAC/D,qBAAgB,GAAhB,gBAAgB,CAAgE;IACxF,CAAC;IAEJ;;;;OAIG;IACH,WAAW,CAAC,KAAoB;QAC9B,IAAI,IAAI,GAAgB,IAAI,CAAC,wBAAwB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QACxF,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAC3C,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;QAC7C,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAC3C,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;;OAKG;IACH,eAAe,CAAC,EAAyC,EAAE,KAAoB;QAC7E,IAAI,IAAI,GAAgB,IAAI,CAAC,wBAAwB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QACxF,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE;YAC5B,GAAG,CAAC,K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AAE,GAAG,IAAI,CAAA;YAC7B,6CAA6C;YAC7C,IAAI,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAA;YACnG,OAAO,IAAI,CAAA;QACb,CAAC,EAAE,QAAQ,CAAC,CAAA;IACd,CAAC;IAEO,sBAAsB,CAAC,MAAsB;QACnD,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,CAAA;QAC9B,MAAM,gBAAgB,GAAG,IAAA,mCAAe,EAAC,MAAM,CAAC,CAAA;QAChD,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;QACrF,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,GAAG,EAAuB,CAAC,CAAA;IACvH,CAAC;IAED,IAAY,aAAa;QACvB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC,CAAA;IACnD,CAAC;CACF;AA9MD,gDA8MC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./aggregate.builder"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./filter-query.builder"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./sql-comparison.builder"), exports);
|
|
7
|
+
(0, tslib_1.__exportStar)(require("./where.builder"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/query-sequelize/src/query/index.ts"],"names":[],"mappings":";;;AAAA,mEAAmC;AACnC,sEAAsC;AACtC,wEAAwC;AACxC,+DAA+B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CommonFieldComparisonBetweenType, FilterComparisonOperators } from '@ptc-org/nestjs-query-core';
|
|
2
|
+
import { WhereOptions } from 'sequelize';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare type EntityComparisonField<Entity, F extends keyof Entity> = Entity[F] | Entity[F][] | CommonFieldComparisonBetweenType<Entity[F]> | true | false | null;
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
* Builder to create SQL Comparisons. (=, !=, \>, etc...)
|
|
10
|
+
*/
|
|
11
|
+
export declare class SQLComparisonBuilder<Entity> {
|
|
12
|
+
readonly comparisonMap: Record<string, symbol>;
|
|
13
|
+
static DEFAULT_COMPARISON_MAP: Record<string, symbol>;
|
|
14
|
+
constructor(comparisonMap?: Record<string, symbol>);
|
|
15
|
+
/**
|
|
16
|
+
* Creates a valid SQL fragment with parameters.
|
|
17
|
+
*
|
|
18
|
+
* @param field - the property in Entity to create the comparison for.
|
|
19
|
+
* @param cmp - the FilterComparisonOperator (eq, neq, gt, etc...)
|
|
20
|
+
* @param val - the value to compare to.
|
|
21
|
+
*/
|
|
22
|
+
build<F extends keyof Entity>(field: F, cmp: FilterComparisonOperators<Entity[F]>, val: EntityComparisonField<Entity, F>, alias?: string): WhereOptions;
|
|
23
|
+
private betweenComparisonSQL;
|
|
24
|
+
private notBetweenComparisonSQL;
|
|
25
|
+
private isBetweenVal;
|
|
26
|
+
}
|