tg-client-query-builder 2.12.2 → 2.14.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/build/query-builder/index.js +33 -20
- package/package.json +4 -4
- package/query-builder/index.js +94 -147
- package/yarn.lock +0 -1659
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
// valid filters:
|
3
|
+
// valid filters:
|
4
4
|
// greaterThan
|
5
5
|
// inList
|
6
6
|
// lessThan
|
@@ -16,11 +16,14 @@
|
|
16
16
|
// endsWithExactly
|
17
17
|
// containsExactly
|
18
18
|
// startsWith
|
19
|
+
// notStartsWith
|
19
20
|
// endsWith
|
21
|
+
// notEndsWith
|
20
22
|
// contains
|
23
|
+
// notContains
|
21
24
|
// upperCase
|
22
25
|
// lowerCase
|
23
|
-
// matchesRegex (note: this takes a string like "thomas.*is.*cool", don't include the outer slashes like /asdf/ and don't pass a regex object )
|
26
|
+
// matchesRegex (note: this takes a string like "thomas.*is.*cool", don't include the outer slashes like /asdf/ and don't pass a regex object )
|
24
27
|
// fuzzy
|
25
28
|
var FilterExpression = require("./filter-expression");
|
26
29
|
var _ = require("lodash");
|
@@ -35,7 +38,7 @@ function isDateOrNumber(opName) {
|
|
35
38
|
if (args.some(function (arg) {
|
36
39
|
return !(_.isDate(arg) || _.isString(arg) || _.isNumber(arg));
|
37
40
|
})) {
|
38
|
-
throw new Error("QueryBuilderError: You must pass a date or number as args to " + opName + ". You passed: Args " + args.join(
|
41
|
+
throw new Error("QueryBuilderError: You must pass a date or number as args to " + opName + ". You passed: Args " + args.join(","));
|
39
42
|
}
|
40
43
|
};
|
41
44
|
}
|
@@ -107,9 +110,15 @@ var expressionOperators = [{
|
|
107
110
|
}, {
|
108
111
|
opName: "startsWith",
|
109
112
|
sanityChecks: [numberOfArgs("startsWith", 1), isString("startsWith")]
|
113
|
+
}, {
|
114
|
+
opName: "notStartsWith",
|
115
|
+
sanityChecks: [numberOfArgs("notStartsWith", 1), isString("notStartsWith")]
|
110
116
|
}, {
|
111
117
|
opName: "endsWith",
|
112
118
|
sanityChecks: [numberOfArgs("endsWith", 1), isString("endsWith")]
|
119
|
+
}, {
|
120
|
+
opName: "notEndsWith",
|
121
|
+
sanityChecks: [numberOfArgs("notEndsWith", 1), isString("notEndsWith")]
|
113
122
|
}, {
|
114
123
|
opName: "contains",
|
115
124
|
sanityChecks: [numberOfArgs("contains", 1), isString("contains")]
|
@@ -125,26 +134,26 @@ var expressionOperators = [{
|
|
125
134
|
}, {
|
126
135
|
opName: "matchesRegex",
|
127
136
|
sanityChecks: [numberOfArgs("matchesRegex", 1), isString("matchesRegex")]
|
137
|
+
}, {
|
138
|
+
opName: "matchesSimilar",
|
139
|
+
sanityChecks: [numberOfArgs("matchesSimilar", 1), isString("matchesSimilar")]
|
128
140
|
}, {
|
129
141
|
opName: "fuzzy",
|
130
142
|
sanityChecks: [numberOfArgs("fuzzy", 1), isString("fuzzy")],
|
131
143
|
transform: function transform(arg) {
|
132
|
-
// Build Regex String
|
133
|
-
var matchTerm =
|
144
|
+
// Build Regex String
|
145
|
+
var matchTerm = "";
|
134
146
|
// Split all the search terms
|
135
|
-
var terms = arg.replace(/\W/g,
|
147
|
+
var terms = arg.replace(/\W/g, "").replace(" ", "").split("");
|
136
148
|
for (var i = 0; i < terms.length; i++) {
|
137
|
-
matchTerm +=
|
149
|
+
matchTerm += ".*" + terms[i];
|
138
150
|
}
|
139
|
-
matchTerm +=
|
151
|
+
matchTerm += ".*";
|
140
152
|
return {
|
141
|
-
newOpName:
|
153
|
+
newOpName: "matchesRegex",
|
142
154
|
newArgs: [matchTerm]
|
143
155
|
};
|
144
156
|
}
|
145
|
-
|
146
|
-
// 'subString', //tnr: not yet implemented
|
147
|
-
// 'dateOnly', //tnr: not yet implemented
|
148
157
|
}];
|
149
158
|
|
150
159
|
module.exports = function () {
|
@@ -218,7 +227,7 @@ module.exports = function () {
|
|
218
227
|
};
|
219
228
|
};
|
220
229
|
|
221
|
-
QueryBuilder.prototype.related = function (relatedEntity) {
|
230
|
+
QueryBuilder.prototype.related = function (relatedEntity, isArrayRelation) {
|
222
231
|
var tokens = relatedEntity.split(".");
|
223
232
|
var entity = tokens[0];
|
224
233
|
var key = tokens[1];
|
@@ -226,10 +235,10 @@ module.exports = function () {
|
|
226
235
|
// log("FilterBuilder in related");
|
227
236
|
// log(FilterBuilder);
|
228
237
|
|
229
|
-
return createSubQueryBuilder(this, entity, key);
|
238
|
+
return createSubQueryBuilder(this, entity, key, isArrayRelation);
|
230
239
|
};
|
231
240
|
|
232
|
-
QueryBuilder.prototype.notRelated = function (relatedEntity) {
|
241
|
+
QueryBuilder.prototype.notRelated = function (relatedEntity, isArrayRelation) {
|
233
242
|
var tokens = relatedEntity.split(".");
|
234
243
|
var entity = tokens[0];
|
235
244
|
var key = tokens[1];
|
@@ -237,7 +246,7 @@ module.exports = function () {
|
|
237
246
|
// log("FilterBuilder in notRelated");
|
238
247
|
// log(FilterBuilder);
|
239
248
|
|
240
|
-
return createSubQueryBuilder(this, entity, key, "not");
|
249
|
+
return createSubQueryBuilder(this, entity, key, isArrayRelation, "not");
|
241
250
|
};
|
242
251
|
|
243
252
|
QueryBuilder.prototype.toJSON = function () {
|
@@ -245,8 +254,8 @@ module.exports = function () {
|
|
245
254
|
if (qry.filters.length > 1) {
|
246
255
|
qry.filters = [{
|
247
256
|
type: "group",
|
248
|
-
operator:
|
249
|
-
chainedWith:
|
257
|
+
operator: "and",
|
258
|
+
chainedWith: "and",
|
250
259
|
filters: qry.filters
|
251
260
|
}];
|
252
261
|
}
|
@@ -359,12 +368,16 @@ module.exports = function () {
|
|
359
368
|
|
360
369
|
return QueryBuilder;
|
361
370
|
|
362
|
-
function createSubQueryBuilder(qb, entity, key
|
371
|
+
function createSubQueryBuilder(qb, entity, key) {
|
372
|
+
var isArrayRelation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
373
|
+
var modifier = arguments[4];
|
374
|
+
|
363
375
|
return new QueryBuilder({
|
364
376
|
parentBuilder: qb,
|
365
377
|
entity: entity,
|
366
378
|
key: key,
|
367
|
-
modifier: modifier
|
379
|
+
modifier: modifier,
|
380
|
+
isArrayRelation: isArrayRelation
|
368
381
|
});
|
369
382
|
}
|
370
383
|
|
package/package.json
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
{
|
2
2
|
"name": "tg-client-query-builder",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.14.1",
|
4
4
|
"description": "Teselagen Client Side (browser) SQL Query Builder",
|
5
5
|
"main": "build/query-builder/index.js",
|
6
6
|
"repository": "https://github.com/TeselaGen/tg-query.git",
|
7
7
|
"author": "TeselaGen",
|
8
8
|
"license": "ISC",
|
9
9
|
"scripts": {
|
10
|
+
"prepublishOnly": "yarn build",
|
10
11
|
"build": "babel --presets=es2015 query-builder/ --out-dir build/query-builder/"
|
11
12
|
},
|
12
|
-
"prepublish": "yarn build",
|
13
13
|
"dependencies": {
|
14
14
|
"lodash": "^4.17.4"
|
15
15
|
},
|
16
16
|
"devDependencies": {
|
17
|
-
"chai": "^4.0.2",
|
18
|
-
"fs-extra": "^3.0.1",
|
19
17
|
"babel-cli": "^6.26.0",
|
20
18
|
"babel-preset-latest": "^6.24.1",
|
19
|
+
"chai": "^4.0.2",
|
20
|
+
"fs-extra": "^3.0.1",
|
21
21
|
"json-beautify": "^1.0.1",
|
22
22
|
"json-format": "^1.0.1",
|
23
23
|
"jsonfile": "^3.0.0"
|
package/query-builder/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
// valid filters:
|
1
|
+
// valid filters:
|
2
2
|
// greaterThan
|
3
3
|
// inList
|
4
4
|
// lessThan
|
@@ -14,222 +14,170 @@
|
|
14
14
|
// endsWithExactly
|
15
15
|
// containsExactly
|
16
16
|
// startsWith
|
17
|
+
// notStartsWith
|
17
18
|
// endsWith
|
19
|
+
// notEndsWith
|
18
20
|
// contains
|
21
|
+
// notContains
|
19
22
|
// upperCase
|
20
23
|
// lowerCase
|
21
|
-
// matchesRegex (note: this takes a string like "thomas.*is.*cool", don't include the outer slashes like /asdf/ and don't pass a regex object )
|
24
|
+
// matchesRegex (note: this takes a string like "thomas.*is.*cool", don't include the outer slashes like /asdf/ and don't pass a regex object )
|
22
25
|
// fuzzy
|
23
26
|
const FilterExpression = require("./filter-expression");
|
24
27
|
const _ = require("lodash");
|
25
28
|
|
26
|
-
|
27
29
|
const combineQueries = require("./combine-queries");
|
28
30
|
|
29
31
|
function isDateOrNumber(opName) {
|
30
32
|
return () => {
|
31
33
|
var args = [].slice.call(arguments);
|
32
|
-
if (
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
);
|
34
|
+
if (
|
35
|
+
args.some((arg) => {
|
36
|
+
return !(_.isDate(arg) || _.isString(arg) || _.isNumber(arg));
|
37
|
+
})
|
38
|
+
) {
|
39
|
+
throw new Error(`QueryBuilderError: You must pass a date or number as args to ${opName}. You passed: Args ${args.join(",")}`);
|
38
40
|
}
|
39
|
-
}
|
41
|
+
};
|
40
42
|
}
|
41
43
|
function isArray(opName) {
|
42
44
|
return (arg) => {
|
43
45
|
if (!_.isArray(arg)) {
|
44
|
-
throw new Error(
|
45
|
-
`QueryBuilderError: You must pass an array for ${opName} filters. You passed: ${arg}`
|
46
|
-
);
|
46
|
+
throw new Error(`QueryBuilderError: You must pass an array for ${opName} filters. You passed: ${arg}`);
|
47
47
|
}
|
48
|
-
}
|
48
|
+
};
|
49
49
|
}
|
50
50
|
function isString(opName) {
|
51
51
|
return (arg) => {
|
52
52
|
if (!_.isString(arg)) {
|
53
|
-
throw new Error(
|
54
|
-
`QueryBuilderError: You must pass a string for ${opName} filters. You passed: ${arg}`
|
55
|
-
);
|
53
|
+
throw new Error(`QueryBuilderError: You must pass a string for ${opName} filters. You passed: ${arg}`);
|
56
54
|
}
|
57
|
-
}
|
55
|
+
};
|
58
56
|
}
|
59
57
|
|
60
58
|
function numberOfArgs(opName, argLength) {
|
61
59
|
return (...args) => {
|
62
60
|
if (args.length !== argLength) {
|
63
|
-
throw new Error(
|
64
|
-
`QueryBuilderError: Args for ${opName} are of length ${args.length}, but they should be of length ${argLength}`
|
65
|
-
);
|
61
|
+
throw new Error(`QueryBuilderError: Args for ${opName} are of length ${args.length}, but they should be of length ${argLength}`);
|
66
62
|
}
|
67
63
|
};
|
68
64
|
}
|
69
65
|
|
70
|
-
|
71
66
|
const expressionOperators = [
|
72
67
|
{
|
73
68
|
opName: "greaterThan",
|
74
|
-
sanityChecks: [
|
75
|
-
numberOfArgs("greaterThan", 1),
|
76
|
-
isDateOrNumber("greaterThan")
|
77
|
-
]
|
69
|
+
sanityChecks: [numberOfArgs("greaterThan", 1), isDateOrNumber("greaterThan")],
|
78
70
|
},
|
79
71
|
{
|
80
72
|
opName: "inList",
|
81
|
-
sanityChecks: [numberOfArgs("inList", 1), isArray("inList")]
|
73
|
+
sanityChecks: [numberOfArgs("inList", 1), isArray("inList")],
|
82
74
|
},
|
83
75
|
{
|
84
76
|
opName: "lessThan",
|
85
|
-
sanityChecks: [
|
86
|
-
numberOfArgs("lessThan", 1),
|
87
|
-
isDateOrNumber("lessThan"),
|
88
|
-
]
|
77
|
+
sanityChecks: [numberOfArgs("lessThan", 1), isDateOrNumber("lessThan")],
|
89
78
|
},
|
90
79
|
{
|
91
80
|
opName: "lessThanOrEqual",
|
92
|
-
sanityChecks: [
|
93
|
-
numberOfArgs("lessThanOrEqual", 1),
|
94
|
-
isDateOrNumber("lessThanOrEqual"),
|
95
|
-
]
|
81
|
+
sanityChecks: [numberOfArgs("lessThanOrEqual", 1), isDateOrNumber("lessThanOrEqual")],
|
96
82
|
},
|
97
83
|
{
|
98
84
|
opName: "equals",
|
99
|
-
sanityChecks: [
|
100
|
-
numberOfArgs("equals", 1),
|
101
|
-
]
|
85
|
+
sanityChecks: [numberOfArgs("equals", 1)],
|
102
86
|
},
|
103
87
|
{
|
104
88
|
opName: "greaterThanOrEqual",
|
105
|
-
sanityChecks: [
|
106
|
-
numberOfArgs("greaterThanOrEqual", 1),
|
107
|
-
isDateOrNumber("greaterThanOrEqual"),
|
108
|
-
]
|
89
|
+
sanityChecks: [numberOfArgs("greaterThanOrEqual", 1), isDateOrNumber("greaterThanOrEqual")],
|
109
90
|
},
|
110
91
|
{
|
111
92
|
opName: "notEquals",
|
112
|
-
sanityChecks: [
|
113
|
-
numberOfArgs("notEquals", 1),
|
114
|
-
]
|
93
|
+
sanityChecks: [numberOfArgs("notEquals", 1)],
|
115
94
|
},
|
116
95
|
{
|
117
96
|
opName: "notNull",
|
118
|
-
sanityChecks: [
|
119
|
-
numberOfArgs("notNull", 0),
|
120
|
-
]
|
97
|
+
sanityChecks: [numberOfArgs("notNull", 0)],
|
121
98
|
},
|
122
99
|
{
|
123
100
|
opName: "isNull",
|
124
|
-
sanityChecks: [
|
125
|
-
numberOfArgs("isNull", 0),
|
126
|
-
]
|
101
|
+
sanityChecks: [numberOfArgs("isNull", 0)],
|
127
102
|
},
|
128
103
|
{
|
129
104
|
opName: "between",
|
130
|
-
sanityChecks: [
|
131
|
-
numberOfArgs("between", 2),
|
132
|
-
isDateOrNumber("between"),
|
133
|
-
]
|
105
|
+
sanityChecks: [numberOfArgs("between", 2), isDateOrNumber("between")],
|
134
106
|
},
|
135
107
|
{
|
136
108
|
opName: "notInList",
|
137
|
-
sanityChecks: [
|
138
|
-
numberOfArgs("notInList", 1),
|
139
|
-
isArray("notInList"),
|
140
|
-
]
|
109
|
+
sanityChecks: [numberOfArgs("notInList", 1), isArray("notInList")],
|
141
110
|
},
|
142
111
|
{
|
143
112
|
opName: "startsWithExactly",
|
144
|
-
sanityChecks: [
|
145
|
-
numberOfArgs("startsWith", 1),
|
146
|
-
isString("startsWith")
|
147
|
-
]
|
113
|
+
sanityChecks: [numberOfArgs("startsWith", 1), isString("startsWith")],
|
148
114
|
},
|
149
115
|
{
|
150
116
|
opName: "endsWithExactly",
|
151
|
-
sanityChecks: [
|
152
|
-
numberOfArgs("endsWith", 1),
|
153
|
-
isString("endsWith")
|
154
|
-
]
|
117
|
+
sanityChecks: [numberOfArgs("endsWith", 1), isString("endsWith")],
|
155
118
|
},
|
156
119
|
{
|
157
120
|
opName: "containsExactly",
|
158
|
-
sanityChecks: [
|
159
|
-
numberOfArgs("contains", 1),
|
160
|
-
isString("contains")
|
161
|
-
]
|
121
|
+
sanityChecks: [numberOfArgs("contains", 1), isString("contains")],
|
162
122
|
},
|
163
123
|
{
|
164
124
|
opName: "startsWith",
|
165
|
-
sanityChecks: [
|
166
|
-
|
167
|
-
|
168
|
-
|
125
|
+
sanityChecks: [numberOfArgs("startsWith", 1), isString("startsWith")],
|
126
|
+
},
|
127
|
+
{
|
128
|
+
opName: "notStartsWith",
|
129
|
+
sanityChecks: [numberOfArgs("notStartsWith", 1), isString("notStartsWith")],
|
169
130
|
},
|
170
131
|
{
|
171
132
|
opName: "endsWith",
|
172
|
-
sanityChecks: [
|
173
|
-
|
174
|
-
|
175
|
-
|
133
|
+
sanityChecks: [numberOfArgs("endsWith", 1), isString("endsWith")],
|
134
|
+
},
|
135
|
+
{
|
136
|
+
opName: "notEndsWith",
|
137
|
+
sanityChecks: [numberOfArgs("notEndsWith", 1), isString("notEndsWith")],
|
176
138
|
},
|
177
139
|
{
|
178
140
|
opName: "contains",
|
179
|
-
sanityChecks: [
|
180
|
-
numberOfArgs("contains", 1),
|
181
|
-
isString("contains")
|
182
|
-
]
|
141
|
+
sanityChecks: [numberOfArgs("contains", 1), isString("contains")],
|
183
142
|
},
|
184
143
|
{
|
185
144
|
opName: "notContains",
|
186
|
-
sanityChecks: [
|
187
|
-
numberOfArgs("notContains", 1),
|
188
|
-
isString("notContains")
|
189
|
-
]
|
145
|
+
sanityChecks: [numberOfArgs("notContains", 1), isString("notContains")],
|
190
146
|
},
|
191
147
|
{
|
192
148
|
opName: "upperCase",
|
193
|
-
sanityChecks: [
|
194
|
-
numberOfArgs("upperCase", 1),
|
195
|
-
isString("upperCase")
|
196
|
-
]
|
149
|
+
sanityChecks: [numberOfArgs("upperCase", 1), isString("upperCase")],
|
197
150
|
},
|
198
151
|
{
|
199
152
|
opName: "lowerCase",
|
200
|
-
sanityChecks: [
|
201
|
-
numberOfArgs("lowerCase", 1),
|
202
|
-
isString("lowerCase")
|
203
|
-
]
|
153
|
+
sanityChecks: [numberOfArgs("lowerCase", 1), isString("lowerCase")],
|
204
154
|
},
|
205
155
|
{
|
206
156
|
opName: "matchesRegex",
|
207
|
-
sanityChecks: [
|
208
|
-
|
209
|
-
|
210
|
-
|
157
|
+
sanityChecks: [numberOfArgs("matchesRegex", 1), isString("matchesRegex")],
|
158
|
+
},
|
159
|
+
{
|
160
|
+
opName: "matchesSimilar",
|
161
|
+
sanityChecks: [numberOfArgs("matchesSimilar", 1), isString("matchesSimilar")],
|
211
162
|
},
|
212
163
|
{
|
213
164
|
opName: "fuzzy",
|
214
|
-
sanityChecks: [
|
215
|
-
numberOfArgs("fuzzy", 1),
|
216
|
-
isString("fuzzy")
|
217
|
-
],
|
165
|
+
sanityChecks: [numberOfArgs("fuzzy", 1), isString("fuzzy")],
|
218
166
|
transform: (arg) => {
|
219
|
-
// Build Regex String
|
220
|
-
var matchTerm =
|
167
|
+
// Build Regex String
|
168
|
+
var matchTerm = "";
|
221
169
|
// Split all the search terms
|
222
|
-
var terms = arg.replace(/\W/g,
|
170
|
+
var terms = arg.replace(/\W/g, "").replace(" ", "").split("");
|
223
171
|
for (var i = 0; i < terms.length; i++) {
|
224
|
-
matchTerm +=
|
172
|
+
matchTerm += ".*" + terms[i];
|
225
173
|
}
|
226
|
-
matchTerm +=
|
174
|
+
matchTerm += ".*";
|
227
175
|
return {
|
228
|
-
newOpName:
|
229
|
-
newArgs: [matchTerm]
|
230
|
-
}
|
231
|
-
}
|
232
|
-
}
|
176
|
+
newOpName: "matchesRegex",
|
177
|
+
newArgs: [matchTerm],
|
178
|
+
};
|
179
|
+
},
|
180
|
+
},
|
233
181
|
|
234
182
|
// 'subString', //tnr: not yet implemented
|
235
183
|
// 'dateOnly', //tnr: not yet implemented
|
@@ -269,15 +217,14 @@ module.exports = (function () {
|
|
269
217
|
function QueryBuilder(entity) {
|
270
218
|
this.query = {};
|
271
219
|
|
272
|
-
if (entity == null)
|
273
|
-
throw new Error("You must pass the name of the model being filtered!");
|
220
|
+
if (entity == null) throw new Error("You must pass the name of the model being filtered!");
|
274
221
|
|
275
222
|
if (typeof entity === "string") {
|
276
223
|
this.query = {
|
277
224
|
__objectType: "query",
|
278
225
|
type: "root",
|
279
226
|
entity,
|
280
|
-
filters: []
|
227
|
+
filters: [],
|
281
228
|
};
|
282
229
|
} else {
|
283
230
|
let subQuery = entity;
|
@@ -288,7 +235,7 @@ module.exports = (function () {
|
|
288
235
|
foreignKey: subQuery.foreignKey,
|
289
236
|
modifier: subQuery.modifier,
|
290
237
|
filters: [],
|
291
|
-
countExpression: undefined
|
238
|
+
countExpression: undefined,
|
292
239
|
};
|
293
240
|
this.parentBuilder = subQuery.parentBuilder;
|
294
241
|
this.toFilter = function (filterBuilder, name) {
|
@@ -303,11 +250,11 @@ module.exports = (function () {
|
|
303
250
|
QueryBuilder.prototype.field = function (fieldName) {
|
304
251
|
return {
|
305
252
|
__objectType: "field",
|
306
|
-
field: fieldName
|
253
|
+
field: fieldName,
|
307
254
|
};
|
308
255
|
};
|
309
256
|
|
310
|
-
QueryBuilder.prototype.related = function (relatedEntity) {
|
257
|
+
QueryBuilder.prototype.related = function (relatedEntity, isArrayRelation) {
|
311
258
|
var tokens = relatedEntity.split(".");
|
312
259
|
var entity = tokens[0];
|
313
260
|
var key = tokens[1];
|
@@ -315,10 +262,10 @@ module.exports = (function () {
|
|
315
262
|
// log("FilterBuilder in related");
|
316
263
|
// log(FilterBuilder);
|
317
264
|
|
318
|
-
return createSubQueryBuilder(this, entity, key);
|
265
|
+
return createSubQueryBuilder(this, entity, key, isArrayRelation);
|
319
266
|
};
|
320
267
|
|
321
|
-
QueryBuilder.prototype.notRelated = function (relatedEntity) {
|
268
|
+
QueryBuilder.prototype.notRelated = function (relatedEntity, isArrayRelation) {
|
322
269
|
var tokens = relatedEntity.split(".");
|
323
270
|
var entity = tokens[0];
|
324
271
|
var key = tokens[1];
|
@@ -326,7 +273,7 @@ module.exports = (function () {
|
|
326
273
|
// log("FilterBuilder in notRelated");
|
327
274
|
// log(FilterBuilder);
|
328
275
|
|
329
|
-
return createSubQueryBuilder(this, entity, key, "not");
|
276
|
+
return createSubQueryBuilder(this, entity, key, isArrayRelation, "not");
|
330
277
|
};
|
331
278
|
|
332
279
|
QueryBuilder.prototype.toJSON = function () {
|
@@ -335,10 +282,10 @@ module.exports = (function () {
|
|
335
282
|
qry.filters = [
|
336
283
|
{
|
337
284
|
type: "group",
|
338
|
-
operator:
|
339
|
-
chainedWith:
|
340
|
-
filters: qry.filters
|
341
|
-
}
|
285
|
+
operator: "and",
|
286
|
+
chainedWith: "and",
|
287
|
+
filters: qry.filters,
|
288
|
+
},
|
342
289
|
];
|
343
290
|
}
|
344
291
|
return qry;
|
@@ -357,7 +304,7 @@ module.exports = (function () {
|
|
357
304
|
// }
|
358
305
|
if (!isFilterExpresionOrSubQuery(name, arg)) {
|
359
306
|
if (Array.isArray(arg)) {
|
360
|
-
filters.push(this.inList(arg).toFilter(this, name))
|
307
|
+
filters.push(this.inList(arg).toFilter(this, name));
|
361
308
|
} else {
|
362
309
|
//log("Is Where Filter: " + name);
|
363
310
|
whereArgs[name] = arg;
|
@@ -370,7 +317,7 @@ module.exports = (function () {
|
|
370
317
|
if (_.keys(whereArgs).length > 0) {
|
371
318
|
filters.unshift({
|
372
319
|
type: "where",
|
373
|
-
args: whereArgs
|
320
|
+
args: whereArgs,
|
374
321
|
});
|
375
322
|
}
|
376
323
|
|
@@ -380,7 +327,7 @@ module.exports = (function () {
|
|
380
327
|
var filterDef = {
|
381
328
|
type: "group",
|
382
329
|
operator: operator || "and",
|
383
|
-
filters
|
330
|
+
filters,
|
384
331
|
};
|
385
332
|
return filterDef;
|
386
333
|
};
|
@@ -434,9 +381,7 @@ module.exports = (function () {
|
|
434
381
|
var args = [].slice.call(arguments);
|
435
382
|
if (this.query.type === "subquery") {
|
436
383
|
if (this.query.countExpression) {
|
437
|
-
throw new Error(
|
438
|
-
"QueryBuilder subquery can only have one count expression"
|
439
|
-
);
|
384
|
+
throw new Error("QueryBuilder subquery can only have one count expression");
|
440
385
|
}
|
441
386
|
this.query.countExpression = args[0].toFilter(this, "count");
|
442
387
|
} else {
|
@@ -450,30 +395,33 @@ module.exports = (function () {
|
|
450
395
|
|
451
396
|
return QueryBuilder;
|
452
397
|
|
453
|
-
function createSubQueryBuilder(qb, entity, key, modifier) {
|
398
|
+
function createSubQueryBuilder(qb, entity, key, isArrayRelation = true, modifier) {
|
454
399
|
return new QueryBuilder({
|
455
400
|
parentBuilder: qb,
|
456
401
|
entity,
|
457
402
|
key,
|
458
|
-
modifier
|
403
|
+
modifier,
|
404
|
+
isArrayRelation,
|
459
405
|
});
|
460
406
|
}
|
461
407
|
|
462
408
|
function attachExpressionFunctions() {
|
463
409
|
expressionOperators.forEach(({ opName, sanityChecks, transform }) => {
|
464
|
-
const filter = (...args)=> {
|
465
|
-
let argsToUse = args
|
466
|
-
let opNameToUse = opName
|
410
|
+
const filter = (...args) => {
|
411
|
+
let argsToUse = args;
|
412
|
+
let opNameToUse = opName;
|
467
413
|
if (transform) {
|
468
|
-
let { newOpName, newArgs } = transform(...args)
|
469
|
-
argsToUse = newArgs
|
470
|
-
opNameToUse = newOpName
|
414
|
+
let { newOpName, newArgs } = transform(...args);
|
415
|
+
argsToUse = newArgs;
|
416
|
+
opNameToUse = newOpName;
|
471
417
|
}
|
472
|
-
sanityChecks.forEach((sanityCheck) => {
|
418
|
+
sanityChecks.forEach((sanityCheck) => {
|
419
|
+
sanityCheck(...args);
|
420
|
+
});
|
473
421
|
return new FilterExpression(opNameToUse, argsToUse);
|
474
422
|
};
|
475
|
-
QueryBuilder.prototype[opName] = filter
|
476
|
-
QueryBuilder.ExpressionJson[opName] = filter
|
423
|
+
QueryBuilder.prototype[opName] = filter;
|
424
|
+
QueryBuilder.ExpressionJson[opName] = filter;
|
477
425
|
});
|
478
426
|
}
|
479
427
|
|
@@ -492,17 +440,16 @@ module.exports = (function () {
|
|
492
440
|
}
|
493
441
|
|
494
442
|
function where(filterBuilder, operator, whereArgs, chainedWith) {
|
495
|
-
if (!Array.isArray(whereArgs))
|
496
|
-
return where(filterBuilder, operator, [whereArgs], chainedWith);
|
443
|
+
if (!Array.isArray(whereArgs)) return where(filterBuilder, operator, [whereArgs], chainedWith);
|
497
444
|
|
498
445
|
var filterDef = {
|
499
446
|
type: "group",
|
500
447
|
operator,
|
501
448
|
chainedWith,
|
502
|
-
filters: []
|
449
|
+
filters: [],
|
503
450
|
};
|
504
451
|
|
505
|
-
whereArgs.forEach(arg => {
|
452
|
+
whereArgs.forEach((arg) => {
|
506
453
|
//add check for object type TODO
|
507
454
|
var filter = filterBuilder.convertToFilter(arg, operator);
|
508
455
|
filterDef.filters.push(filter);
|