tg-client-query-builder 2.13.1 → 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 +24 -20
- package/package.json +4 -4
- package/query-builder/index.js +85 -155
@@ -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
|
@@ -23,7 +23,7 @@
|
|
23
23
|
// notContains
|
24
24
|
// upperCase
|
25
25
|
// lowerCase
|
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 )
|
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 )
|
27
27
|
// fuzzy
|
28
28
|
var FilterExpression = require("./filter-expression");
|
29
29
|
var _ = require("lodash");
|
@@ -38,7 +38,7 @@ function isDateOrNumber(opName) {
|
|
38
38
|
if (args.some(function (arg) {
|
39
39
|
return !(_.isDate(arg) || _.isString(arg) || _.isNumber(arg));
|
40
40
|
})) {
|
41
|
-
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(","));
|
42
42
|
}
|
43
43
|
};
|
44
44
|
}
|
@@ -134,26 +134,26 @@ var expressionOperators = [{
|
|
134
134
|
}, {
|
135
135
|
opName: "matchesRegex",
|
136
136
|
sanityChecks: [numberOfArgs("matchesRegex", 1), isString("matchesRegex")]
|
137
|
+
}, {
|
138
|
+
opName: "matchesSimilar",
|
139
|
+
sanityChecks: [numberOfArgs("matchesSimilar", 1), isString("matchesSimilar")]
|
137
140
|
}, {
|
138
141
|
opName: "fuzzy",
|
139
142
|
sanityChecks: [numberOfArgs("fuzzy", 1), isString("fuzzy")],
|
140
143
|
transform: function transform(arg) {
|
141
|
-
// Build Regex String
|
142
|
-
var matchTerm =
|
144
|
+
// Build Regex String
|
145
|
+
var matchTerm = "";
|
143
146
|
// Split all the search terms
|
144
|
-
var terms = arg.replace(/\W/g,
|
147
|
+
var terms = arg.replace(/\W/g, "").replace(" ", "").split("");
|
145
148
|
for (var i = 0; i < terms.length; i++) {
|
146
|
-
matchTerm +=
|
149
|
+
matchTerm += ".*" + terms[i];
|
147
150
|
}
|
148
|
-
matchTerm +=
|
151
|
+
matchTerm += ".*";
|
149
152
|
return {
|
150
|
-
newOpName:
|
153
|
+
newOpName: "matchesRegex",
|
151
154
|
newArgs: [matchTerm]
|
152
155
|
};
|
153
156
|
}
|
154
|
-
|
155
|
-
// 'subString', //tnr: not yet implemented
|
156
|
-
// 'dateOnly', //tnr: not yet implemented
|
157
157
|
}];
|
158
158
|
|
159
159
|
module.exports = function () {
|
@@ -227,7 +227,7 @@ module.exports = function () {
|
|
227
227
|
};
|
228
228
|
};
|
229
229
|
|
230
|
-
QueryBuilder.prototype.related = function (relatedEntity) {
|
230
|
+
QueryBuilder.prototype.related = function (relatedEntity, isArrayRelation) {
|
231
231
|
var tokens = relatedEntity.split(".");
|
232
232
|
var entity = tokens[0];
|
233
233
|
var key = tokens[1];
|
@@ -235,10 +235,10 @@ module.exports = function () {
|
|
235
235
|
// log("FilterBuilder in related");
|
236
236
|
// log(FilterBuilder);
|
237
237
|
|
238
|
-
return createSubQueryBuilder(this, entity, key);
|
238
|
+
return createSubQueryBuilder(this, entity, key, isArrayRelation);
|
239
239
|
};
|
240
240
|
|
241
|
-
QueryBuilder.prototype.notRelated = function (relatedEntity) {
|
241
|
+
QueryBuilder.prototype.notRelated = function (relatedEntity, isArrayRelation) {
|
242
242
|
var tokens = relatedEntity.split(".");
|
243
243
|
var entity = tokens[0];
|
244
244
|
var key = tokens[1];
|
@@ -246,7 +246,7 @@ module.exports = function () {
|
|
246
246
|
// log("FilterBuilder in notRelated");
|
247
247
|
// log(FilterBuilder);
|
248
248
|
|
249
|
-
return createSubQueryBuilder(this, entity, key, "not");
|
249
|
+
return createSubQueryBuilder(this, entity, key, isArrayRelation, "not");
|
250
250
|
};
|
251
251
|
|
252
252
|
QueryBuilder.prototype.toJSON = function () {
|
@@ -254,8 +254,8 @@ module.exports = function () {
|
|
254
254
|
if (qry.filters.length > 1) {
|
255
255
|
qry.filters = [{
|
256
256
|
type: "group",
|
257
|
-
operator:
|
258
|
-
chainedWith:
|
257
|
+
operator: "and",
|
258
|
+
chainedWith: "and",
|
259
259
|
filters: qry.filters
|
260
260
|
}];
|
261
261
|
}
|
@@ -368,12 +368,16 @@ module.exports = function () {
|
|
368
368
|
|
369
369
|
return QueryBuilder;
|
370
370
|
|
371
|
-
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
|
+
|
372
375
|
return new QueryBuilder({
|
373
376
|
parentBuilder: qb,
|
374
377
|
entity: entity,
|
375
378
|
key: key,
|
376
|
-
modifier: modifier
|
379
|
+
modifier: modifier,
|
380
|
+
isArrayRelation: isArrayRelation
|
377
381
|
});
|
378
382
|
}
|
379
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
|
@@ -21,232 +21,163 @@
|
|
21
21
|
// notContains
|
22
22
|
// upperCase
|
23
23
|
// lowerCase
|
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 )
|
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 )
|
25
25
|
// fuzzy
|
26
26
|
const FilterExpression = require("./filter-expression");
|
27
27
|
const _ = require("lodash");
|
28
28
|
|
29
|
-
|
30
29
|
const combineQueries = require("./combine-queries");
|
31
30
|
|
32
31
|
function isDateOrNumber(opName) {
|
33
32
|
return () => {
|
34
33
|
var args = [].slice.call(arguments);
|
35
|
-
if (
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
);
|
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(",")}`);
|
41
40
|
}
|
42
|
-
}
|
41
|
+
};
|
43
42
|
}
|
44
43
|
function isArray(opName) {
|
45
44
|
return (arg) => {
|
46
45
|
if (!_.isArray(arg)) {
|
47
|
-
throw new Error(
|
48
|
-
`QueryBuilderError: You must pass an array for ${opName} filters. You passed: ${arg}`
|
49
|
-
);
|
46
|
+
throw new Error(`QueryBuilderError: You must pass an array for ${opName} filters. You passed: ${arg}`);
|
50
47
|
}
|
51
|
-
}
|
48
|
+
};
|
52
49
|
}
|
53
50
|
function isString(opName) {
|
54
51
|
return (arg) => {
|
55
52
|
if (!_.isString(arg)) {
|
56
|
-
throw new Error(
|
57
|
-
`QueryBuilderError: You must pass a string for ${opName} filters. You passed: ${arg}`
|
58
|
-
);
|
53
|
+
throw new Error(`QueryBuilderError: You must pass a string for ${opName} filters. You passed: ${arg}`);
|
59
54
|
}
|
60
|
-
}
|
55
|
+
};
|
61
56
|
}
|
62
57
|
|
63
58
|
function numberOfArgs(opName, argLength) {
|
64
59
|
return (...args) => {
|
65
60
|
if (args.length !== argLength) {
|
66
|
-
throw new Error(
|
67
|
-
`QueryBuilderError: Args for ${opName} are of length ${args.length}, but they should be of length ${argLength}`
|
68
|
-
);
|
61
|
+
throw new Error(`QueryBuilderError: Args for ${opName} are of length ${args.length}, but they should be of length ${argLength}`);
|
69
62
|
}
|
70
63
|
};
|
71
64
|
}
|
72
65
|
|
73
|
-
|
74
66
|
const expressionOperators = [
|
75
67
|
{
|
76
68
|
opName: "greaterThan",
|
77
|
-
sanityChecks: [
|
78
|
-
numberOfArgs("greaterThan", 1),
|
79
|
-
isDateOrNumber("greaterThan")
|
80
|
-
]
|
69
|
+
sanityChecks: [numberOfArgs("greaterThan", 1), isDateOrNumber("greaterThan")],
|
81
70
|
},
|
82
71
|
{
|
83
72
|
opName: "inList",
|
84
|
-
sanityChecks: [numberOfArgs("inList", 1), isArray("inList")]
|
73
|
+
sanityChecks: [numberOfArgs("inList", 1), isArray("inList")],
|
85
74
|
},
|
86
75
|
{
|
87
76
|
opName: "lessThan",
|
88
|
-
sanityChecks: [
|
89
|
-
numberOfArgs("lessThan", 1),
|
90
|
-
isDateOrNumber("lessThan"),
|
91
|
-
]
|
77
|
+
sanityChecks: [numberOfArgs("lessThan", 1), isDateOrNumber("lessThan")],
|
92
78
|
},
|
93
79
|
{
|
94
80
|
opName: "lessThanOrEqual",
|
95
|
-
sanityChecks: [
|
96
|
-
numberOfArgs("lessThanOrEqual", 1),
|
97
|
-
isDateOrNumber("lessThanOrEqual"),
|
98
|
-
]
|
81
|
+
sanityChecks: [numberOfArgs("lessThanOrEqual", 1), isDateOrNumber("lessThanOrEqual")],
|
99
82
|
},
|
100
83
|
{
|
101
84
|
opName: "equals",
|
102
|
-
sanityChecks: [
|
103
|
-
numberOfArgs("equals", 1),
|
104
|
-
]
|
85
|
+
sanityChecks: [numberOfArgs("equals", 1)],
|
105
86
|
},
|
106
87
|
{
|
107
88
|
opName: "greaterThanOrEqual",
|
108
|
-
sanityChecks: [
|
109
|
-
numberOfArgs("greaterThanOrEqual", 1),
|
110
|
-
isDateOrNumber("greaterThanOrEqual"),
|
111
|
-
]
|
89
|
+
sanityChecks: [numberOfArgs("greaterThanOrEqual", 1), isDateOrNumber("greaterThanOrEqual")],
|
112
90
|
},
|
113
91
|
{
|
114
92
|
opName: "notEquals",
|
115
|
-
sanityChecks: [
|
116
|
-
numberOfArgs("notEquals", 1),
|
117
|
-
]
|
93
|
+
sanityChecks: [numberOfArgs("notEquals", 1)],
|
118
94
|
},
|
119
95
|
{
|
120
96
|
opName: "notNull",
|
121
|
-
sanityChecks: [
|
122
|
-
numberOfArgs("notNull", 0),
|
123
|
-
]
|
97
|
+
sanityChecks: [numberOfArgs("notNull", 0)],
|
124
98
|
},
|
125
99
|
{
|
126
100
|
opName: "isNull",
|
127
|
-
sanityChecks: [
|
128
|
-
numberOfArgs("isNull", 0),
|
129
|
-
]
|
101
|
+
sanityChecks: [numberOfArgs("isNull", 0)],
|
130
102
|
},
|
131
103
|
{
|
132
104
|
opName: "between",
|
133
|
-
sanityChecks: [
|
134
|
-
numberOfArgs("between", 2),
|
135
|
-
isDateOrNumber("between"),
|
136
|
-
]
|
105
|
+
sanityChecks: [numberOfArgs("between", 2), isDateOrNumber("between")],
|
137
106
|
},
|
138
107
|
{
|
139
108
|
opName: "notInList",
|
140
|
-
sanityChecks: [
|
141
|
-
numberOfArgs("notInList", 1),
|
142
|
-
isArray("notInList"),
|
143
|
-
]
|
109
|
+
sanityChecks: [numberOfArgs("notInList", 1), isArray("notInList")],
|
144
110
|
},
|
145
111
|
{
|
146
112
|
opName: "startsWithExactly",
|
147
|
-
sanityChecks: [
|
148
|
-
numberOfArgs("startsWith", 1),
|
149
|
-
isString("startsWith")
|
150
|
-
]
|
113
|
+
sanityChecks: [numberOfArgs("startsWith", 1), isString("startsWith")],
|
151
114
|
},
|
152
115
|
{
|
153
116
|
opName: "endsWithExactly",
|
154
|
-
sanityChecks: [
|
155
|
-
numberOfArgs("endsWith", 1),
|
156
|
-
isString("endsWith")
|
157
|
-
]
|
117
|
+
sanityChecks: [numberOfArgs("endsWith", 1), isString("endsWith")],
|
158
118
|
},
|
159
119
|
{
|
160
120
|
opName: "containsExactly",
|
161
|
-
sanityChecks: [
|
162
|
-
numberOfArgs("contains", 1),
|
163
|
-
isString("contains")
|
164
|
-
]
|
121
|
+
sanityChecks: [numberOfArgs("contains", 1), isString("contains")],
|
165
122
|
},
|
166
123
|
{
|
167
124
|
opName: "startsWith",
|
168
|
-
sanityChecks: [
|
169
|
-
numberOfArgs("startsWith", 1),
|
170
|
-
isString("startsWith")
|
171
|
-
]
|
125
|
+
sanityChecks: [numberOfArgs("startsWith", 1), isString("startsWith")],
|
172
126
|
},
|
173
127
|
{
|
174
128
|
opName: "notStartsWith",
|
175
|
-
sanityChecks: [
|
176
|
-
numberOfArgs("notStartsWith", 1),
|
177
|
-
isString("notStartsWith")
|
178
|
-
]
|
129
|
+
sanityChecks: [numberOfArgs("notStartsWith", 1), isString("notStartsWith")],
|
179
130
|
},
|
180
131
|
{
|
181
132
|
opName: "endsWith",
|
182
|
-
sanityChecks: [
|
183
|
-
numberOfArgs("endsWith", 1),
|
184
|
-
isString("endsWith")
|
185
|
-
]
|
133
|
+
sanityChecks: [numberOfArgs("endsWith", 1), isString("endsWith")],
|
186
134
|
},
|
187
135
|
{
|
188
136
|
opName: "notEndsWith",
|
189
|
-
sanityChecks: [
|
190
|
-
numberOfArgs("notEndsWith", 1),
|
191
|
-
isString("notEndsWith")
|
192
|
-
]
|
137
|
+
sanityChecks: [numberOfArgs("notEndsWith", 1), isString("notEndsWith")],
|
193
138
|
},
|
194
139
|
{
|
195
140
|
opName: "contains",
|
196
|
-
sanityChecks: [
|
197
|
-
numberOfArgs("contains", 1),
|
198
|
-
isString("contains")
|
199
|
-
]
|
141
|
+
sanityChecks: [numberOfArgs("contains", 1), isString("contains")],
|
200
142
|
},
|
201
143
|
{
|
202
144
|
opName: "notContains",
|
203
|
-
sanityChecks: [
|
204
|
-
numberOfArgs("notContains", 1),
|
205
|
-
isString("notContains")
|
206
|
-
]
|
145
|
+
sanityChecks: [numberOfArgs("notContains", 1), isString("notContains")],
|
207
146
|
},
|
208
147
|
{
|
209
148
|
opName: "upperCase",
|
210
|
-
sanityChecks: [
|
211
|
-
numberOfArgs("upperCase", 1),
|
212
|
-
isString("upperCase")
|
213
|
-
]
|
149
|
+
sanityChecks: [numberOfArgs("upperCase", 1), isString("upperCase")],
|
214
150
|
},
|
215
151
|
{
|
216
152
|
opName: "lowerCase",
|
217
|
-
sanityChecks: [
|
218
|
-
numberOfArgs("lowerCase", 1),
|
219
|
-
isString("lowerCase")
|
220
|
-
]
|
153
|
+
sanityChecks: [numberOfArgs("lowerCase", 1), isString("lowerCase")],
|
221
154
|
},
|
222
155
|
{
|
223
156
|
opName: "matchesRegex",
|
224
|
-
sanityChecks: [
|
225
|
-
|
226
|
-
|
227
|
-
|
157
|
+
sanityChecks: [numberOfArgs("matchesRegex", 1), isString("matchesRegex")],
|
158
|
+
},
|
159
|
+
{
|
160
|
+
opName: "matchesSimilar",
|
161
|
+
sanityChecks: [numberOfArgs("matchesSimilar", 1), isString("matchesSimilar")],
|
228
162
|
},
|
229
163
|
{
|
230
164
|
opName: "fuzzy",
|
231
|
-
sanityChecks: [
|
232
|
-
numberOfArgs("fuzzy", 1),
|
233
|
-
isString("fuzzy")
|
234
|
-
],
|
165
|
+
sanityChecks: [numberOfArgs("fuzzy", 1), isString("fuzzy")],
|
235
166
|
transform: (arg) => {
|
236
|
-
// Build Regex String
|
237
|
-
var matchTerm =
|
167
|
+
// Build Regex String
|
168
|
+
var matchTerm = "";
|
238
169
|
// Split all the search terms
|
239
|
-
var terms = arg.replace(/\W/g,
|
170
|
+
var terms = arg.replace(/\W/g, "").replace(" ", "").split("");
|
240
171
|
for (var i = 0; i < terms.length; i++) {
|
241
|
-
matchTerm +=
|
172
|
+
matchTerm += ".*" + terms[i];
|
242
173
|
}
|
243
|
-
matchTerm +=
|
174
|
+
matchTerm += ".*";
|
244
175
|
return {
|
245
|
-
newOpName:
|
246
|
-
newArgs: [matchTerm]
|
247
|
-
}
|
248
|
-
}
|
249
|
-
}
|
176
|
+
newOpName: "matchesRegex",
|
177
|
+
newArgs: [matchTerm],
|
178
|
+
};
|
179
|
+
},
|
180
|
+
},
|
250
181
|
|
251
182
|
// 'subString', //tnr: not yet implemented
|
252
183
|
// 'dateOnly', //tnr: not yet implemented
|
@@ -286,15 +217,14 @@ module.exports = (function () {
|
|
286
217
|
function QueryBuilder(entity) {
|
287
218
|
this.query = {};
|
288
219
|
|
289
|
-
if (entity == null)
|
290
|
-
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!");
|
291
221
|
|
292
222
|
if (typeof entity === "string") {
|
293
223
|
this.query = {
|
294
224
|
__objectType: "query",
|
295
225
|
type: "root",
|
296
226
|
entity,
|
297
|
-
filters: []
|
227
|
+
filters: [],
|
298
228
|
};
|
299
229
|
} else {
|
300
230
|
let subQuery = entity;
|
@@ -305,7 +235,7 @@ module.exports = (function () {
|
|
305
235
|
foreignKey: subQuery.foreignKey,
|
306
236
|
modifier: subQuery.modifier,
|
307
237
|
filters: [],
|
308
|
-
countExpression: undefined
|
238
|
+
countExpression: undefined,
|
309
239
|
};
|
310
240
|
this.parentBuilder = subQuery.parentBuilder;
|
311
241
|
this.toFilter = function (filterBuilder, name) {
|
@@ -320,11 +250,11 @@ module.exports = (function () {
|
|
320
250
|
QueryBuilder.prototype.field = function (fieldName) {
|
321
251
|
return {
|
322
252
|
__objectType: "field",
|
323
|
-
field: fieldName
|
253
|
+
field: fieldName,
|
324
254
|
};
|
325
255
|
};
|
326
256
|
|
327
|
-
QueryBuilder.prototype.related = function (relatedEntity) {
|
257
|
+
QueryBuilder.prototype.related = function (relatedEntity, isArrayRelation) {
|
328
258
|
var tokens = relatedEntity.split(".");
|
329
259
|
var entity = tokens[0];
|
330
260
|
var key = tokens[1];
|
@@ -332,10 +262,10 @@ module.exports = (function () {
|
|
332
262
|
// log("FilterBuilder in related");
|
333
263
|
// log(FilterBuilder);
|
334
264
|
|
335
|
-
return createSubQueryBuilder(this, entity, key);
|
265
|
+
return createSubQueryBuilder(this, entity, key, isArrayRelation);
|
336
266
|
};
|
337
267
|
|
338
|
-
QueryBuilder.prototype.notRelated = function (relatedEntity) {
|
268
|
+
QueryBuilder.prototype.notRelated = function (relatedEntity, isArrayRelation) {
|
339
269
|
var tokens = relatedEntity.split(".");
|
340
270
|
var entity = tokens[0];
|
341
271
|
var key = tokens[1];
|
@@ -343,7 +273,7 @@ module.exports = (function () {
|
|
343
273
|
// log("FilterBuilder in notRelated");
|
344
274
|
// log(FilterBuilder);
|
345
275
|
|
346
|
-
return createSubQueryBuilder(this, entity, key, "not");
|
276
|
+
return createSubQueryBuilder(this, entity, key, isArrayRelation, "not");
|
347
277
|
};
|
348
278
|
|
349
279
|
QueryBuilder.prototype.toJSON = function () {
|
@@ -352,10 +282,10 @@ module.exports = (function () {
|
|
352
282
|
qry.filters = [
|
353
283
|
{
|
354
284
|
type: "group",
|
355
|
-
operator:
|
356
|
-
chainedWith:
|
357
|
-
filters: qry.filters
|
358
|
-
}
|
285
|
+
operator: "and",
|
286
|
+
chainedWith: "and",
|
287
|
+
filters: qry.filters,
|
288
|
+
},
|
359
289
|
];
|
360
290
|
}
|
361
291
|
return qry;
|
@@ -374,7 +304,7 @@ module.exports = (function () {
|
|
374
304
|
// }
|
375
305
|
if (!isFilterExpresionOrSubQuery(name, arg)) {
|
376
306
|
if (Array.isArray(arg)) {
|
377
|
-
filters.push(this.inList(arg).toFilter(this, name))
|
307
|
+
filters.push(this.inList(arg).toFilter(this, name));
|
378
308
|
} else {
|
379
309
|
//log("Is Where Filter: " + name);
|
380
310
|
whereArgs[name] = arg;
|
@@ -387,7 +317,7 @@ module.exports = (function () {
|
|
387
317
|
if (_.keys(whereArgs).length > 0) {
|
388
318
|
filters.unshift({
|
389
319
|
type: "where",
|
390
|
-
args: whereArgs
|
320
|
+
args: whereArgs,
|
391
321
|
});
|
392
322
|
}
|
393
323
|
|
@@ -397,7 +327,7 @@ module.exports = (function () {
|
|
397
327
|
var filterDef = {
|
398
328
|
type: "group",
|
399
329
|
operator: operator || "and",
|
400
|
-
filters
|
330
|
+
filters,
|
401
331
|
};
|
402
332
|
return filterDef;
|
403
333
|
};
|
@@ -451,9 +381,7 @@ module.exports = (function () {
|
|
451
381
|
var args = [].slice.call(arguments);
|
452
382
|
if (this.query.type === "subquery") {
|
453
383
|
if (this.query.countExpression) {
|
454
|
-
throw new Error(
|
455
|
-
"QueryBuilder subquery can only have one count expression"
|
456
|
-
);
|
384
|
+
throw new Error("QueryBuilder subquery can only have one count expression");
|
457
385
|
}
|
458
386
|
this.query.countExpression = args[0].toFilter(this, "count");
|
459
387
|
} else {
|
@@ -467,30 +395,33 @@ module.exports = (function () {
|
|
467
395
|
|
468
396
|
return QueryBuilder;
|
469
397
|
|
470
|
-
function createSubQueryBuilder(qb, entity, key, modifier) {
|
398
|
+
function createSubQueryBuilder(qb, entity, key, isArrayRelation = true, modifier) {
|
471
399
|
return new QueryBuilder({
|
472
400
|
parentBuilder: qb,
|
473
401
|
entity,
|
474
402
|
key,
|
475
|
-
modifier
|
403
|
+
modifier,
|
404
|
+
isArrayRelation,
|
476
405
|
});
|
477
406
|
}
|
478
407
|
|
479
408
|
function attachExpressionFunctions() {
|
480
409
|
expressionOperators.forEach(({ opName, sanityChecks, transform }) => {
|
481
|
-
const filter = (...args)=> {
|
482
|
-
let argsToUse = args
|
483
|
-
let opNameToUse = opName
|
410
|
+
const filter = (...args) => {
|
411
|
+
let argsToUse = args;
|
412
|
+
let opNameToUse = opName;
|
484
413
|
if (transform) {
|
485
|
-
let { newOpName, newArgs } = transform(...args)
|
486
|
-
argsToUse = newArgs
|
487
|
-
opNameToUse = newOpName
|
414
|
+
let { newOpName, newArgs } = transform(...args);
|
415
|
+
argsToUse = newArgs;
|
416
|
+
opNameToUse = newOpName;
|
488
417
|
}
|
489
|
-
sanityChecks.forEach((sanityCheck) => {
|
418
|
+
sanityChecks.forEach((sanityCheck) => {
|
419
|
+
sanityCheck(...args);
|
420
|
+
});
|
490
421
|
return new FilterExpression(opNameToUse, argsToUse);
|
491
422
|
};
|
492
|
-
QueryBuilder.prototype[opName] = filter
|
493
|
-
QueryBuilder.ExpressionJson[opName] = filter
|
423
|
+
QueryBuilder.prototype[opName] = filter;
|
424
|
+
QueryBuilder.ExpressionJson[opName] = filter;
|
494
425
|
});
|
495
426
|
}
|
496
427
|
|
@@ -509,17 +440,16 @@ module.exports = (function () {
|
|
509
440
|
}
|
510
441
|
|
511
442
|
function where(filterBuilder, operator, whereArgs, chainedWith) {
|
512
|
-
if (!Array.isArray(whereArgs))
|
513
|
-
return where(filterBuilder, operator, [whereArgs], chainedWith);
|
443
|
+
if (!Array.isArray(whereArgs)) return where(filterBuilder, operator, [whereArgs], chainedWith);
|
514
444
|
|
515
445
|
var filterDef = {
|
516
446
|
type: "group",
|
517
447
|
operator,
|
518
448
|
chainedWith,
|
519
|
-
filters: []
|
449
|
+
filters: [],
|
520
450
|
};
|
521
451
|
|
522
|
-
whereArgs.forEach(arg => {
|
452
|
+
whereArgs.forEach((arg) => {
|
523
453
|
//add check for object type TODO
|
524
454
|
var filter = filterBuilder.convertToFilter(arg, operator);
|
525
455
|
filterDef.filters.push(filter);
|