@scx-js/scx-data 0.2.4 → 0.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/LICENSE +21 -0
- package/README.md +20 -0
- package/field_policy/AssignField.js +3 -3
- package/field_policy/FieldPolicy.js +6 -0
- package/field_policy/FieldPolicyBuilder.js +16 -3
- package/field_policy/FieldPolicyImpl.js +54 -17
- package/field_policy/FilterMode.js +20 -3
- package/field_policy/VirtualField.js +3 -3
- package/index.js +8 -7
- package/package.json +3 -6
- package/query/And.js +2 -2
- package/query/BuildControl.js +27 -4
- package/query/Condition.js +6 -10
- package/query/ConditionType.js +29 -70
- package/query/Junction.js +35 -27
- package/query/Not.js +1 -0
- package/query/Or.js +2 -2
- package/query/OrderBy.js +5 -7
- package/query/OrderByType.js +16 -2
- package/query/QueryBuilder.js +36 -18
- package/query/QueryImpl.js +39 -19
- package/query/QueryLike.js +7 -1
- package/query/SkipIfInfo.js +21 -28
- package/query/WhereClause.js +1 -5
- package/x/FieldPolicyNodeConverter.js +73 -0
- package/x/QueryNodeConverter.js +163 -0
- package/serialization/FieldPolicySerializer.js +0 -47
- package/serialization/QuerySerializer.js +0 -120
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 scx567888
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://js.scx.dev/scx-logo/scx-data-logo.svg" width="300px" alt="scx-data-logo"/>
|
|
3
|
+
</p>
|
|
4
|
+
<p align="center">
|
|
5
|
+
<a target="_blank" href="https://github.com/scx-js/scx-data/actions/workflows/ci.yml">
|
|
6
|
+
<img src="https://github.com/scx-js/scx-data/actions/workflows/ci.yml/badge.svg" alt="CI"/>
|
|
7
|
+
</a>
|
|
8
|
+
<a target="_blank" href="https://www.npmjs.com/package/@scx-js/scx-data">
|
|
9
|
+
<img src="https://img.shields.io/npm/v/@scx-js/scx-data.svg?color=ff69b4" alt="npm"/>
|
|
10
|
+
</a>
|
|
11
|
+
<a target="_blank" href="https://github.com/scx-js/scx-data">
|
|
12
|
+
<img src="https://img.shields.io/github/languages/code-size/scx-js/scx-data?color=orange" alt="code-size"/>
|
|
13
|
+
</a>
|
|
14
|
+
<a target="_blank" href="https://github.com/scx-js/scx-data/issues">
|
|
15
|
+
<img src="https://img.shields.io/github/issues/scx-js/scx-data" alt="issues"/>
|
|
16
|
+
</a>
|
|
17
|
+
<a target="_blank" href="https://github.com/scx-js/scx-data/blob/master/LICENSE">
|
|
18
|
+
<img src="https://img.shields.io/github/license/scx-js/scx-data" alt="license"/>
|
|
19
|
+
</a>
|
|
20
|
+
</p>
|
|
@@ -10,10 +10,10 @@ class AssignField extends FieldPolicyLike {
|
|
|
10
10
|
constructor(fieldName, expression) {
|
|
11
11
|
super();
|
|
12
12
|
if (fieldName == null) {
|
|
13
|
-
throw new Error("fieldName
|
|
13
|
+
throw new Error("fieldName cannot be null");
|
|
14
14
|
}
|
|
15
15
|
if (expression == null) {
|
|
16
|
-
throw new Error("expression
|
|
16
|
+
throw new Error("expression cannot be null");
|
|
17
17
|
}
|
|
18
18
|
this.#fieldName = fieldName;
|
|
19
19
|
this.#expression = expression;
|
|
@@ -28,7 +28,7 @@ class AssignField extends FieldPolicyLike {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
toFieldPolicy() {
|
|
31
|
-
|
|
31
|
+
// 默认包含所有 (includeAll)
|
|
32
32
|
return new FieldPolicyImpl(EXCLUDED).assignFields(this);
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -9,9 +9,11 @@ class FieldPolicy {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
getFilterMode() {
|
|
12
|
+
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
getFieldNames() {
|
|
16
|
+
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
clearFieldNames() {
|
|
@@ -23,6 +25,7 @@ class FieldPolicy {
|
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
getVirtualFields() {
|
|
28
|
+
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
clearVirtualFields() {
|
|
@@ -46,12 +49,15 @@ class FieldPolicy {
|
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
getIgnoreNull() {
|
|
52
|
+
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
getIgnoreNulls() {
|
|
56
|
+
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
getAssignFields() {
|
|
60
|
+
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
clearIgnoreNulls() {
|
|
@@ -19,21 +19,32 @@ function exclude(...fieldNames) {
|
|
|
19
19
|
return includeAll().exclude(...fieldNames);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/// 默认包含所有
|
|
22
|
+
/// 默认包含所有 (includeAll)
|
|
23
23
|
function ignoreNull(ignoreNull) {
|
|
24
24
|
return includeAll().ignoreNull(ignoreNull);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
/// 默认包含所有
|
|
27
|
+
/// 默认包含所有 (includeAll)
|
|
28
28
|
function ignoreNull_(fieldName, ignoreNull) {
|
|
29
29
|
return includeAll().ignoreNull_(fieldName, ignoreNull);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/// 默认包含所有
|
|
32
|
+
/// 默认包含所有 (includeAll)
|
|
33
|
+
function assignFields(...assignFields) {
|
|
34
|
+
return includeAll().assignFields(...assignFields);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/// 默认包含所有 (includeAll)
|
|
38
|
+
function virtualFields(...virtualFields) {
|
|
39
|
+
return includeAll().virtualFields(...virtualFields);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/// 默认包含所有 (includeAll)
|
|
33
43
|
function assignField(fieldName, expression) {
|
|
34
44
|
return new AssignField(fieldName, expression);
|
|
35
45
|
}
|
|
36
46
|
|
|
47
|
+
/// 默认包含所有 (includeAll)
|
|
37
48
|
function virtualField(virtualFieldName, expression) {
|
|
38
49
|
return new VirtualField(virtualFieldName, expression);
|
|
39
50
|
}
|
|
@@ -45,6 +56,8 @@ export {
|
|
|
45
56
|
exclude,
|
|
46
57
|
ignoreNull,
|
|
47
58
|
ignoreNull_,
|
|
59
|
+
assignFields,
|
|
60
|
+
virtualFields,
|
|
48
61
|
assignField,
|
|
49
62
|
virtualField,
|
|
50
63
|
};
|
|
@@ -14,11 +14,14 @@ class FieldPolicyImpl extends FieldPolicy {
|
|
|
14
14
|
|
|
15
15
|
constructor(filterMode) {
|
|
16
16
|
super();
|
|
17
|
+
if (filterMode == null) {
|
|
18
|
+
throw new Error("filterMode cannot be null");
|
|
19
|
+
}
|
|
17
20
|
this.#filterMode = filterMode;
|
|
18
|
-
this.#fieldNames = new Set();
|
|
21
|
+
this.#fieldNames = new Set(); // 需要保证顺序
|
|
19
22
|
this.#virtualFields = [];
|
|
20
23
|
this.#assignFields = [];
|
|
21
|
-
this.#ignoreNulls = new Map();
|
|
24
|
+
this.#ignoreNulls = new Map(); // 需要保证顺序
|
|
22
25
|
this.#ignoreNull = true;
|
|
23
26
|
}
|
|
24
27
|
|
|
@@ -51,22 +54,17 @@ class FieldPolicyImpl extends FieldPolicy {
|
|
|
51
54
|
return this;
|
|
52
55
|
}
|
|
53
56
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
virtualFields(...virtualFields) {
|
|
58
|
+
if (virtualFields == null) {
|
|
59
|
+
throw new Error("virtualFields cannot be null");
|
|
57
60
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.#fieldNames.delete(name);
|
|
61
|
+
let newVirtualFields = [];
|
|
62
|
+
for (let virtualField of virtualFields) {
|
|
63
|
+
if (virtualField != null) {
|
|
64
|
+
newVirtualFields.push(virtualField);
|
|
65
|
+
}
|
|
64
66
|
}
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
virtualFields(...virtualFields) {
|
|
69
|
-
this.#virtualFields = [...virtualFields];
|
|
67
|
+
this.#virtualFields = newVirtualFields;
|
|
70
68
|
return this;
|
|
71
69
|
}
|
|
72
70
|
|
|
@@ -90,12 +88,24 @@ class FieldPolicyImpl extends FieldPolicy {
|
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
ignoreNull_(fieldName, ignoreNull) {
|
|
91
|
+
if (fieldName == null) {
|
|
92
|
+
throw new Error("fieldName cannot be null");
|
|
93
|
+
}
|
|
93
94
|
this.#ignoreNulls.set(fieldName, ignoreNull);
|
|
94
95
|
return this;
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
assignFields(...assignFields) {
|
|
98
|
-
|
|
99
|
+
if (assignFields == null) {
|
|
100
|
+
throw new Error("assignFields cannot be null");
|
|
101
|
+
}
|
|
102
|
+
let newAssignFields = [];
|
|
103
|
+
for (let assignField of assignFields) {
|
|
104
|
+
if (assignField != null) {
|
|
105
|
+
newAssignFields.push(assignField);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
this.#assignFields = newAssignFields;
|
|
99
109
|
return this;
|
|
100
110
|
}
|
|
101
111
|
|
|
@@ -122,6 +132,9 @@ class FieldPolicyImpl extends FieldPolicy {
|
|
|
122
132
|
}
|
|
123
133
|
|
|
124
134
|
removeIgnoreNull(fieldName) {
|
|
135
|
+
if (fieldName == null) {
|
|
136
|
+
throw new Error("fieldName cannot be null");
|
|
137
|
+
}
|
|
125
138
|
this.#ignoreNulls.delete(fieldName);
|
|
126
139
|
return this;
|
|
127
140
|
}
|
|
@@ -131,6 +144,30 @@ class FieldPolicyImpl extends FieldPolicy {
|
|
|
131
144
|
return this;
|
|
132
145
|
}
|
|
133
146
|
|
|
147
|
+
addFieldNames(...fieldNames) {
|
|
148
|
+
if (fieldNames == null) {
|
|
149
|
+
throw new Error("fieldNames cannot be null");
|
|
150
|
+
}
|
|
151
|
+
for (const fieldName of fieldNames) {
|
|
152
|
+
if (fieldName != null) {
|
|
153
|
+
this.#fieldNames.add(fieldName);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
removeFieldNames(...fieldNames) {
|
|
160
|
+
if (fieldNames == null) {
|
|
161
|
+
throw new Error("fieldNames cannot be null");
|
|
162
|
+
}
|
|
163
|
+
for (const fieldName of fieldNames) {
|
|
164
|
+
if (fieldName != null) {
|
|
165
|
+
this.#fieldNames.delete(fieldName);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
|
|
134
171
|
}
|
|
135
172
|
|
|
136
173
|
export {FieldPolicyImpl};
|
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
class FilterMode {
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
#value;
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
constructor(value) {
|
|
6
|
+
this.#value = value;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
value() {
|
|
10
|
+
return this.#value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const INCLUDED = new FilterMode("INCLUDED");
|
|
16
|
+
const EXCLUDED = new FilterMode("EXCLUDED");
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
FilterMode,
|
|
20
|
+
INCLUDED,
|
|
21
|
+
EXCLUDED,
|
|
22
|
+
};
|
|
@@ -10,10 +10,10 @@ class VirtualField extends FieldPolicyLike {
|
|
|
10
10
|
constructor(virtualFieldName, expression) {
|
|
11
11
|
super();
|
|
12
12
|
if (virtualFieldName == null) {
|
|
13
|
-
throw new Error("virtualFieldName
|
|
13
|
+
throw new Error("virtualFieldName cannot be null");
|
|
14
14
|
}
|
|
15
15
|
if (expression == null) {
|
|
16
|
-
throw new Error("expression
|
|
16
|
+
throw new Error("expression cannot be null");
|
|
17
17
|
}
|
|
18
18
|
this.#virtualFieldName = virtualFieldName;
|
|
19
19
|
this.#expression = expression;
|
|
@@ -28,7 +28,7 @@ class VirtualField extends FieldPolicyLike {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
toFieldPolicy() {
|
|
31
|
-
|
|
31
|
+
// 默认包含所有 (includeAll)
|
|
32
32
|
return new FieldPolicyImpl(EXCLUDED).virtualFields(this);
|
|
33
33
|
}
|
|
34
34
|
|
package/index.js
CHANGED
|
@@ -5,19 +5,20 @@ export * from "./field_policy/FieldPolicyImpl.js";
|
|
|
5
5
|
export * from "./field_policy/FieldPolicyLike.js";
|
|
6
6
|
export * from "./field_policy/FilterMode.js";
|
|
7
7
|
export * from "./field_policy/VirtualField.js";
|
|
8
|
-
export * from "./query/Junction.js";
|
|
9
8
|
export * from "./query/And.js";
|
|
10
|
-
export * from "./query/
|
|
9
|
+
export * from "./query/BuildControl.js";
|
|
10
|
+
export * from "./query/Condition.js";
|
|
11
|
+
export * from "./query/ConditionType.js";
|
|
12
|
+
export * from "./query/Junction.js";
|
|
11
13
|
export * from "./query/Not.js";
|
|
14
|
+
export * from "./query/Or.js";
|
|
12
15
|
export * from "./query/OrderBy.js";
|
|
13
16
|
export * from "./query/OrderByType.js";
|
|
14
17
|
export * from "./query/Query.js";
|
|
15
18
|
export * from "./query/QueryBuilder.js";
|
|
16
19
|
export * from "./query/QueryImpl.js";
|
|
17
20
|
export * from "./query/QueryLike.js";
|
|
18
|
-
export * from "./query/
|
|
19
|
-
export * from "./query/Condition.js";
|
|
21
|
+
export * from "./query/SkipIfInfo.js";
|
|
20
22
|
export * from "./query/WhereClause.js";
|
|
21
|
-
export * from "./
|
|
22
|
-
export * from "./
|
|
23
|
-
export * from "./serialization/FieldPolicySerializer.js";
|
|
23
|
+
export * from "./x/FieldPolicyNodeConverter.js";
|
|
24
|
+
export * from "./x/QueryNodeConverter.js";
|
package/package.json
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scx-js/scx-data",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "SCX Data",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "scx567888",
|
|
7
|
-
"
|
|
7
|
+
"exports": "./index.js",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/
|
|
12
|
-
},
|
|
13
|
-
"dependencies": {
|
|
14
|
-
"@scx-js/scx-common": "0.2.4"
|
|
11
|
+
"url": "git+https://github.com/scx-js/scx-data.git"
|
|
15
12
|
}
|
|
16
13
|
}
|
package/query/And.js
CHANGED
|
@@ -4,11 +4,11 @@ import {Or} from "./Or.js";
|
|
|
4
4
|
class And extends Junction {
|
|
5
5
|
|
|
6
6
|
and(...clauses) {
|
|
7
|
-
return this.add(new And().add(clauses));
|
|
7
|
+
return this.add(new And().add(...clauses));
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
or(...clauses) {
|
|
11
|
-
return this.add(new Or().add(clauses));
|
|
11
|
+
return this.add(new Or().add(...clauses));
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
}
|
package/query/BuildControl.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {SkipIfInfo} from "./SkipIfInfo.js";
|
|
2
|
+
|
|
1
3
|
class BuildControl {
|
|
2
4
|
|
|
3
5
|
#value;
|
|
@@ -15,8 +17,28 @@ const SKIP_IF_BLANK_STRING = new BuildControl("SKIP_IF_BLANK_STRING");
|
|
|
15
17
|
const USE_EXPRESSION = new BuildControl("USE_EXPRESSION");
|
|
16
18
|
const USE_EXPRESSION_VALUE = new BuildControl("USE_EXPRESSION_VALUE");
|
|
17
19
|
|
|
20
|
+
function toSkipIfInfo(...controls) {
|
|
21
|
+
|
|
22
|
+
let skipIfNull = false;
|
|
23
|
+
let skipIfEmptyList = false;
|
|
24
|
+
let skipIfEmptyString = false;
|
|
25
|
+
let skipIfBlankString = false;
|
|
26
|
+
for (let control of controls) {
|
|
27
|
+
if (control === SKIP_IF_NULL) {
|
|
28
|
+
skipIfNull = true;
|
|
29
|
+
} else if (control === SKIP_IF_EMPTY_LIST) {
|
|
30
|
+
skipIfEmptyList = true;
|
|
31
|
+
} else if (control === SKIP_IF_EMPTY_STRING) {
|
|
32
|
+
skipIfEmptyString = true;
|
|
33
|
+
} else if (control === SKIP_IF_BLANK_STRING) {
|
|
34
|
+
skipIfBlankString = true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return new SkipIfInfo(skipIfNull, skipIfEmptyList, skipIfEmptyString, skipIfBlankString);
|
|
39
|
+
}
|
|
18
40
|
|
|
19
|
-
function
|
|
41
|
+
function toUseExpression(...controls) {
|
|
20
42
|
for (let control of controls) {
|
|
21
43
|
if (control === USE_EXPRESSION) {
|
|
22
44
|
return true;
|
|
@@ -25,7 +47,7 @@ function checkUseExpression(...controls) {
|
|
|
25
47
|
return false;
|
|
26
48
|
}
|
|
27
49
|
|
|
28
|
-
function
|
|
50
|
+
function toUseExpressionValue(...controls) {
|
|
29
51
|
for (let control of controls) {
|
|
30
52
|
if (control === USE_EXPRESSION_VALUE) {
|
|
31
53
|
return true;
|
|
@@ -42,6 +64,7 @@ export {
|
|
|
42
64
|
SKIP_IF_EMPTY_STRING,
|
|
43
65
|
USE_EXPRESSION,
|
|
44
66
|
USE_EXPRESSION_VALUE,
|
|
45
|
-
|
|
46
|
-
|
|
67
|
+
toSkipIfInfo,
|
|
68
|
+
toUseExpression,
|
|
69
|
+
toUseExpressionValue,
|
|
47
70
|
};
|
package/query/Condition.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {QueryLike} from "./QueryLike.js";
|
|
2
|
-
import {isBlank} from "@scx-js/scx-common";
|
|
3
2
|
import {QueryImpl} from "./QueryImpl.js";
|
|
4
3
|
|
|
5
4
|
class Condition extends QueryLike {
|
|
@@ -14,13 +13,14 @@ class Condition extends QueryLike {
|
|
|
14
13
|
|
|
15
14
|
constructor(selector, conditionType, value1, value2, useExpression, useExpressionValue, skipIfInfo) {
|
|
16
15
|
super();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
throw new Error("Where 参数错误 : 名称 不能为空 !!!");
|
|
16
|
+
if (selector == null) {
|
|
17
|
+
throw new Error("selector cannot be null");
|
|
20
18
|
}
|
|
21
|
-
//类型也不能为空
|
|
22
19
|
if (conditionType == null) {
|
|
23
|
-
throw new Error("
|
|
20
|
+
throw new Error("conditionType cannot be null");
|
|
21
|
+
}
|
|
22
|
+
if (skipIfInfo == null) {
|
|
23
|
+
throw new Error("skipIfInfo cannot be null");
|
|
24
24
|
}
|
|
25
25
|
this.#selector = selector;
|
|
26
26
|
this.#conditionType = conditionType;
|
|
@@ -59,10 +59,6 @@ class Condition extends QueryLike {
|
|
|
59
59
|
return this.#skipIfInfo;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
isEmpty() {
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
62
|
toQuery() {
|
|
67
63
|
return new QueryImpl().where(this);
|
|
68
64
|
}
|
package/query/ConditionType.js
CHANGED
|
@@ -1,75 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const GTE = "GTE";
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Like
|
|
33
|
-
*/
|
|
34
|
-
const LIKE = "LIKE";
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Not Like
|
|
38
|
-
*/
|
|
39
|
-
const NOT_LIKE = "NOT_LIKE";
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Like 正则表达式
|
|
43
|
-
*/
|
|
44
|
-
const LIKE_REGEX = "LIKE_REGEX";
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Like 正则表达式
|
|
48
|
-
*/
|
|
49
|
-
const NOT_LIKE_REGEX = "NOT_LIKE_REGEX";
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* IN
|
|
53
|
-
*/
|
|
54
|
-
const IN = "IN";
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* NOT IN
|
|
58
|
-
*/
|
|
59
|
-
const NOT_IN = "NOT_IN";
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* 在之间
|
|
63
|
-
*/
|
|
64
|
-
const BETWEEN = "BETWEEN";
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* 不在之间
|
|
68
|
-
*/
|
|
69
|
-
const NOT_BETWEEN = "NOT_BETWEEN";
|
|
70
|
-
|
|
1
|
+
class ConditionType {
|
|
2
|
+
|
|
3
|
+
#value;
|
|
4
|
+
|
|
5
|
+
constructor(value) {
|
|
6
|
+
this.#value = value;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
value() {
|
|
10
|
+
return this.#value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const EQ = new ConditionType("EQ");
|
|
16
|
+
const NE = new ConditionType("NE");
|
|
17
|
+
const LT = new ConditionType("LT");
|
|
18
|
+
const LTE = new ConditionType("LTE");
|
|
19
|
+
const GT = new ConditionType("GT");
|
|
20
|
+
const GTE = new ConditionType("GTE");
|
|
21
|
+
const LIKE = new ConditionType("LIKE");
|
|
22
|
+
const NOT_LIKE = new ConditionType("NOT_LIKE");
|
|
23
|
+
const LIKE_REGEX = new ConditionType("LIKE_REGEX");
|
|
24
|
+
const NOT_LIKE_REGEX = new ConditionType("NOT_LIKE_REGEX");
|
|
25
|
+
const IN = new ConditionType("IN");
|
|
26
|
+
const NOT_IN = new ConditionType("NOT_IN");
|
|
27
|
+
const BETWEEN = new ConditionType("BETWEEN");
|
|
28
|
+
const NOT_BETWEEN = new ConditionType("NOT_BETWEEN");
|
|
71
29
|
|
|
72
30
|
export {
|
|
31
|
+
ConditionType,
|
|
73
32
|
EQ,
|
|
74
33
|
NE,
|
|
75
34
|
LT,
|
package/query/Junction.js
CHANGED
|
@@ -15,12 +15,11 @@ import {
|
|
|
15
15
|
NOT_LIKE,
|
|
16
16
|
NOT_LIKE_REGEX,
|
|
17
17
|
} from "./ConditionType.js";
|
|
18
|
-
import {Condition} from "./Condition.js";
|
|
19
18
|
import {QueryImpl} from "./QueryImpl.js";
|
|
20
19
|
import {Not} from "./Not.js";
|
|
21
20
|
import {WhereClause} from "./WhereClause.js";
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
21
|
+
import {toSkipIfInfo, toUseExpression, toUseExpressionValue} from "./BuildControl.js";
|
|
22
|
+
import {Condition} from "./Condition.js";
|
|
24
23
|
|
|
25
24
|
class Junction extends QueryLike {
|
|
26
25
|
|
|
@@ -35,8 +34,16 @@ class Junction extends QueryLike {
|
|
|
35
34
|
return this.#clauses;
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
/// null 项会被忽略.
|
|
38
|
+
add(...clauses) {
|
|
39
|
+
if (clauses == null) {
|
|
40
|
+
throw new Error("clauses cannot be null");
|
|
41
|
+
}
|
|
42
|
+
for (let clause of clauses) {
|
|
43
|
+
if (clause != null) {
|
|
44
|
+
this.#clauses.push(clause);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
40
47
|
return this;
|
|
41
48
|
}
|
|
42
49
|
|
|
@@ -45,6 +52,22 @@ class Junction extends QueryLike {
|
|
|
45
52
|
return this;
|
|
46
53
|
}
|
|
47
54
|
|
|
55
|
+
and(...clauses) {
|
|
56
|
+
// 因为 js 不允许 循环依赖 所以 这个方法迁移到子类实现
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
or(...clauses) {
|
|
60
|
+
// 因为 js 不允许 循环依赖 所以 这个方法迁移到子类实现
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
not(clause) {
|
|
64
|
+
return this.add(new Not(clause));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
whereClause(expression, ...params) {
|
|
68
|
+
return this.add(new WhereClause(expression, ...params));
|
|
69
|
+
}
|
|
70
|
+
|
|
48
71
|
eq(fieldName, value, ...options) {
|
|
49
72
|
return this.add(condition(fieldName, EQ, value, ...options));
|
|
50
73
|
}
|
|
@@ -101,40 +124,25 @@ class Junction extends QueryLike {
|
|
|
101
124
|
return this.add(condition2(fieldName, NOT_BETWEEN, value1, value2, ...options));
|
|
102
125
|
}
|
|
103
126
|
|
|
104
|
-
and(...clauses) {
|
|
105
|
-
// 因为 js 不允许 循环依赖 所以 这个方法迁移到子类实现
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
or(...clauses) {
|
|
109
|
-
// 因为 js 不允许 循环依赖 所以 这个方法迁移到子类实现
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
not(clause) {
|
|
113
|
-
return this.add(new Not(clause));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
whereClause(expression, ...params) {
|
|
117
|
-
return this.add(new WhereClause(expression, params));
|
|
118
|
-
}
|
|
119
|
-
|
|
120
127
|
toQuery() {
|
|
121
128
|
return new QueryImpl().where(this);
|
|
122
129
|
}
|
|
123
130
|
|
|
124
131
|
}
|
|
125
132
|
|
|
133
|
+
// 防止循环依赖 QueryBuilder 这里拷贝一份
|
|
126
134
|
|
|
127
135
|
function condition(fieldName, conditionType, value, ...controls) {
|
|
128
|
-
let useExpression =
|
|
129
|
-
let useExpressionValue =
|
|
130
|
-
let skipIfInfo =
|
|
136
|
+
let useExpression = toUseExpression(...controls);
|
|
137
|
+
let useExpressionValue = toUseExpressionValue(...controls);
|
|
138
|
+
let skipIfInfo = toSkipIfInfo(...controls);
|
|
131
139
|
return new Condition(fieldName, conditionType, value, null, useExpression, useExpressionValue, skipIfInfo);
|
|
132
140
|
}
|
|
133
141
|
|
|
134
142
|
function condition2(fieldName, conditionType, value1, value2, ...controls) {
|
|
135
|
-
let useExpression =
|
|
136
|
-
let useExpressionValue =
|
|
137
|
-
let skipIfInfo =
|
|
143
|
+
let useExpression = toUseExpression(...controls);
|
|
144
|
+
let useExpressionValue = toUseExpressionValue(...controls);
|
|
145
|
+
let skipIfInfo = toSkipIfInfo(...controls);
|
|
138
146
|
return new Condition(fieldName, conditionType, value1, value2, useExpression, useExpressionValue, skipIfInfo);
|
|
139
147
|
}
|
|
140
148
|
|