masterrecord 0.0.37 → 0.0.39
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/QueryLanguage/queryManager.js +79 -0
- package/QueryLanguage/queryMethods.js +2 -5
- package/QueryLanguage/queryScript.js +221 -146
- package/SQLLiteEngine.js +38 -31
- package/context.js +1 -1
- package/package.json +5 -5
- package/QueryLanguage/selectManager.js +0 -66
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// ALL THIS SHOULD DO IS BUILD A SQL QUERY
|
|
2
|
+
// version 1.0.1
|
|
3
|
+
|
|
4
|
+
class queryManager{
|
|
5
|
+
constructor( query) {
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
queryObject
|
|
9
|
+
{
|
|
10
|
+
"where": where user.id = 1
|
|
11
|
+
"raw": "select * from tablename where user.id = 2" OR false,
|
|
12
|
+
"builder": builderObject,
|
|
13
|
+
"select" : "*",
|
|
14
|
+
"from" : from tablename
|
|
15
|
+
}
|
|
16
|
+
*/
|
|
17
|
+
this._query = query;
|
|
18
|
+
this._queryBuilder = query.builder;
|
|
19
|
+
this._context = query.builder.__context;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
single(){
|
|
23
|
+
var entityValue = this._context._SQLEngine.get(this._query.getScript());
|
|
24
|
+
var sing = this._queryBuilder.__execute(entityValue, this._queryBuilder);
|
|
25
|
+
return sing;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//
|
|
29
|
+
select(query){
|
|
30
|
+
// this will come after the where
|
|
31
|
+
this._query.select = "select " + query;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
count(){
|
|
36
|
+
// trying to match string select and relace with select Count(*);
|
|
37
|
+
var res = this._query.select.replace("select *", "select Count(*)");
|
|
38
|
+
var entityValue = this._context._SQLEngine.get(res);
|
|
39
|
+
var val = entityValue[Object.keys(entityValue)[0]];
|
|
40
|
+
return val;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
toList(){
|
|
44
|
+
var entityValue = this._context._SQLEngine.all(this._query);
|
|
45
|
+
var toLi = this._queryBuilder.__executeList(entityValue, this._queryBuilder);
|
|
46
|
+
return toLi;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = queryManager;
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
/*
|
|
55
|
+
|
|
56
|
+
LINQ Extension Methods
|
|
57
|
+
First()
|
|
58
|
+
FirstOrDefault()
|
|
59
|
+
SingleOrDefault()
|
|
60
|
+
Count()
|
|
61
|
+
Min()
|
|
62
|
+
Max()
|
|
63
|
+
Last()
|
|
64
|
+
LastOrDefault()
|
|
65
|
+
Average()
|
|
66
|
+
*/
|
|
67
|
+
/*
|
|
68
|
+
|
|
69
|
+
LINQ Extension Methods
|
|
70
|
+
First()
|
|
71
|
+
FirstOrDefault()
|
|
72
|
+
SingleOrDefault()
|
|
73
|
+
Count()
|
|
74
|
+
Min()
|
|
75
|
+
Max()
|
|
76
|
+
Last()
|
|
77
|
+
LastOrDefault()
|
|
78
|
+
Average()
|
|
79
|
+
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
// version 0.0.
|
|
2
|
+
// version 0.0.8
|
|
3
3
|
var entityTrackerModel = require('masterrecord/Entity/entityTrackerModel');
|
|
4
4
|
var tools = require('masterrecord/Tools');
|
|
5
5
|
var queryScript = require('masterrecord/QueryLanguage/queryScript');
|
|
@@ -54,10 +54,6 @@ class queryMethods{
|
|
|
54
54
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
contains(){
|
|
58
|
-
// https://entityframework.net/knowledge-base/3491721/linq-to-entities---where-in-clause-in-query
|
|
59
|
-
}
|
|
60
|
-
|
|
61
57
|
// do join on two tables = inner join
|
|
62
58
|
_____leftJoin(){
|
|
63
59
|
|
|
@@ -137,6 +133,7 @@ class queryMethods{
|
|
|
137
133
|
str = str.replace("$$", item);
|
|
138
134
|
}
|
|
139
135
|
}
|
|
136
|
+
|
|
140
137
|
this.__queryObject.where(str, this.__entity.__name);
|
|
141
138
|
return this;
|
|
142
139
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// version 0.0.
|
|
1
|
+
// version 0.0.3
|
|
2
2
|
|
|
3
3
|
const LOG_OPERATORS_REGEX = /(\|\|)|(&&)/;
|
|
4
4
|
var tools = require('../Tools');
|
|
@@ -63,7 +63,6 @@ class queryScript{
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
where(text, entityName){
|
|
66
|
-
|
|
67
66
|
this.buildScript(text, "where", this.script, entityName);
|
|
68
67
|
return this.script;
|
|
69
68
|
}
|
|
@@ -85,62 +84,58 @@ class queryScript{
|
|
|
85
84
|
|
|
86
85
|
buildScript(text, type, obj, entityName){
|
|
87
86
|
|
|
88
|
-
var
|
|
89
|
-
var cachedExpr = {}; // this function will just get the high leve
|
|
90
|
-
if(groups.length > 0){
|
|
91
|
-
|
|
92
|
-
cachedExpr.entity = this.getEntity(text);
|
|
93
|
-
|
|
94
|
-
if(!this.isMapped(entityName, obj.entityMap)){
|
|
87
|
+
var cachedExpr = {}; // this function will just get the high level
|
|
95
88
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
entity : cachedExpr.entity
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
obj.entity = cachedExpr.entity
|
|
102
|
-
//tools.getRandomLetter(1)
|
|
103
|
-
cachedExpr[entityName] = this.splitGroupsByLogicalOperators(groups);
|
|
89
|
+
/// first we find all the groups in the query string
|
|
90
|
+
var querySections = this.getFunctionsInQuery(text);
|
|
104
91
|
|
|
92
|
+
// remove spaces from query and get the Entity
|
|
93
|
+
cachedExpr.entity = this.getEntity(text);
|
|
94
|
+
|
|
105
95
|
|
|
106
|
-
|
|
107
|
-
this.buildFields(text, cachedExpr);
|
|
96
|
+
if(!this.isMapped(entityName, obj.entityMap)){
|
|
108
97
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
entity : tools.getRandomLetter(1, obj.entityMap)
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
}
|
|
98
|
+
obj.entityMap.push({
|
|
99
|
+
name: entityName,
|
|
100
|
+
entity : cachedExpr.entity
|
|
101
|
+
});
|
|
102
|
+
}
|
|
119
103
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
104
|
+
// attach the entity name to the main Object
|
|
105
|
+
obj.entity = cachedExpr.entity
|
|
106
|
+
|
|
107
|
+
cachedExpr[entityName] = this.splitGroupsByLogicalOperators(querySections.query);
|
|
108
|
+
|
|
109
|
+
// lets break the string into a list of functions
|
|
110
|
+
this.buildFields(text, cachedExpr);
|
|
111
|
+
|
|
112
|
+
if(type === "include"){
|
|
113
|
+
if(cachedExpr.selectFields){
|
|
114
|
+
if(!this.isMapped(cachedExpr.selectFields[0], obj.entityMap)){
|
|
115
|
+
obj.entityMap.push({
|
|
116
|
+
name: tools.capitalizeFirstLetter(cachedExpr.selectFields[0]),
|
|
117
|
+
entity : tools.getRandomLetter(1, obj.entityMap)
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
this.describeExpressionParts(cachedExpr[entityName]);
|
|
124
|
+
this.describeExpressionPartsFunctions(cachedExpr[entityName], querySections.functions);
|
|
125
|
+
if(type === "include" || type === "and"){
|
|
126
|
+
obj[type].push(cachedExpr);
|
|
130
127
|
}
|
|
131
128
|
else{
|
|
132
|
-
|
|
133
|
-
if(type === "select"){
|
|
134
|
-
obj.select = {
|
|
135
|
-
"selectFields": JSON.parse(text)
|
|
136
|
-
}
|
|
137
|
-
return obj.select;
|
|
138
|
-
}
|
|
139
|
-
return null;
|
|
129
|
+
obj[type] = cachedExpr;
|
|
140
130
|
}
|
|
141
131
|
|
|
132
|
+
obj.parentName = entityName;
|
|
133
|
+
return cachedExpr;
|
|
142
134
|
}
|
|
143
135
|
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
// look and grab all fields
|
|
144
139
|
buildFields(text, desc){
|
|
145
140
|
var match = text.match(/^([\w\d$_]+?)\s*=>((?:\{\sreturn\s)?[\s\S]*(?:\})?)/);
|
|
146
141
|
if(match){
|
|
@@ -171,35 +166,38 @@ class queryScript{
|
|
|
171
166
|
+ "\\.((?:\\.?[\\w\\d_\\$]+)+)(?:\\((.*?)\\))?(?:\\s*(>|<|(?:===)|(?:!==)|(?:==)|(?:!=)|(?:=)|(?:<=)|(?:>=)|(?:in))\\s*(.*))?")
|
|
172
167
|
}
|
|
173
168
|
|
|
174
|
-
|
|
169
|
+
|
|
170
|
+
splitGroupsByLogicalOperators(text) {
|
|
175
171
|
let parts = {}, tmp;
|
|
176
|
-
|
|
172
|
+
var part = {query : text, name : "query"}
|
|
177
173
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
part.inside = part.inside.replace("&&", "and");
|
|
189
|
-
part.query = part.query.replace("&&", "and");
|
|
190
|
-
part.inside = part.inside.replace("||", "or");
|
|
191
|
-
part.query = part.query.replace("||", "or");
|
|
174
|
+
//tmp = this.splitByLogicalOperators(part.query, entityRegExp)
|
|
175
|
+
tmp = this.extractInside(part.query, part.name);
|
|
176
|
+
if(tmp){
|
|
177
|
+
part.inside = tmp;
|
|
178
|
+
parts[part.name] = part;
|
|
179
|
+
}
|
|
180
|
+
else{
|
|
181
|
+
part.inside = part.query;
|
|
182
|
+
parts[part.name] = part;
|
|
192
183
|
}
|
|
193
|
-
|
|
184
|
+
part.inside = part.inside.replaceAll("&&", "and");
|
|
185
|
+
part.query = part.query.replaceAll("&&", "and");
|
|
186
|
+
part.inside = part.inside.replaceAll("||", "or");
|
|
187
|
+
part.query = part.query.replaceAll("||", "or");
|
|
188
|
+
|
|
194
189
|
return parts;
|
|
195
190
|
}
|
|
196
191
|
|
|
197
192
|
|
|
198
|
-
|
|
193
|
+
// find all functions from querySections
|
|
194
|
+
getFunctionsInQuery(text) {
|
|
195
|
+
|
|
199
196
|
const regex = /(?<=\.(?=[A-z]+\())([^(]+)\((.+?)\)(?!\))/g;
|
|
200
197
|
let m;
|
|
201
198
|
const items = [];
|
|
202
|
-
|
|
199
|
+
|
|
200
|
+
while ((m = regex.exec(text)) !== null) {
|
|
203
201
|
// This is necessary to avoid infinite loops with zero-width matches
|
|
204
202
|
if (m.index === regex.lastIndex) {
|
|
205
203
|
regex.lastIndex++;
|
|
@@ -207,94 +205,171 @@ class queryScript{
|
|
|
207
205
|
|
|
208
206
|
const [, fName, query] = m;
|
|
209
207
|
items.push(
|
|
210
|
-
{name: fName, query:
|
|
211
|
-
)
|
|
208
|
+
{name: fName, query: query, inside : query, parentFeild : this.getParentField(text, m[0]), input: m.input}
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
text = text.replace(`${fName}(${query})`, `func`);
|
|
212
|
+
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
//items.push({name: "NOFUNCTIONS", query: str})
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
functions: items,
|
|
219
|
+
query : text
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
getParentField(text, funcName){
|
|
224
|
+
var split = text.split(".");
|
|
225
|
+
for (let i = 0; i < split.length; i++) {
|
|
226
|
+
|
|
227
|
+
if(split[i].includes(funcName)){
|
|
228
|
+
return split[i -1];
|
|
229
|
+
}
|
|
212
230
|
}
|
|
213
|
-
|
|
214
|
-
|
|
231
|
+
return "";
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
findExpression(fieldName, expression){
|
|
235
|
+
// loop through and find expression
|
|
236
|
+
for (const key in expression) {
|
|
237
|
+
|
|
238
|
+
if(expression[key].field === fieldName){
|
|
239
|
+
return expression[key]
|
|
240
|
+
}
|
|
215
241
|
}
|
|
216
|
-
return items;
|
|
217
242
|
}
|
|
218
243
|
|
|
244
|
+
describeExpressionPartsFunctions(cachedExpr, functions){
|
|
245
|
+
cachedExpr.functions = [];
|
|
246
|
+
if(functions.length > 0){
|
|
247
|
+
for (let item in functions) {
|
|
248
|
+
|
|
249
|
+
var part = functions[item];
|
|
250
|
+
var partQuery = part.inside;
|
|
251
|
+
// get entity of inside function
|
|
252
|
+
var entity = this.getEntity(partQuery);
|
|
253
|
+
|
|
254
|
+
part.entity = entity;
|
|
255
|
+
|
|
256
|
+
// is the function name white listed
|
|
257
|
+
if(this.isFunction(part.name)){
|
|
258
|
+
var scriptInner = {
|
|
259
|
+
select : false,
|
|
260
|
+
where: false,
|
|
261
|
+
and : [],
|
|
262
|
+
include : [],
|
|
263
|
+
raw: false,
|
|
264
|
+
entity : "",
|
|
265
|
+
entityMap : [],
|
|
266
|
+
take : 0,
|
|
267
|
+
skip: 0,
|
|
268
|
+
orderBy : false,
|
|
269
|
+
orderByDesc : false
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
if(part.name === "where"){
|
|
273
|
+
// TODO: we need to Get this working
|
|
274
|
+
// recall to parse inner query of function that is being called
|
|
275
|
+
this.buildScript(part.inside, part.name, scriptInner, part.parentFeild);
|
|
276
|
+
part.parentName = scriptInner.parentName;
|
|
277
|
+
part.entity = scriptInner.where.entity;
|
|
278
|
+
part.expr = scriptInner.where.expr;
|
|
279
|
+
part.selectFields = scriptInner.where.selectFields;
|
|
280
|
+
part[scriptInner.parentName] = scriptInner.where[scriptInner.parentName];
|
|
281
|
+
}
|
|
282
|
+
if(part.name === "include"){
|
|
283
|
+
// TODO: we need to Get this working
|
|
284
|
+
// recall to parse inner query of function that is being called
|
|
285
|
+
this.buildScript(part.inside, part.name, scriptInner, part.parentFeild);
|
|
286
|
+
part.parentName = scriptInner.parentName;
|
|
287
|
+
part.entity = scriptInner.include.entity;
|
|
288
|
+
part.expr = scriptInner.include.expr;
|
|
289
|
+
part.selectFields = scriptInner.include.selectFields;
|
|
290
|
+
part[scriptInner.parentName] = scriptInner.include[scriptInner.parentName];
|
|
291
|
+
|
|
292
|
+
}
|
|
293
|
+
if(part.name === "select"){
|
|
294
|
+
// TODO: we need to Get this working
|
|
295
|
+
// recall to parse inner query of function that is being called
|
|
296
|
+
this.buildScript(part.inside, part.name, scriptInner, part.parentFeild);
|
|
297
|
+
part.parentName = scriptInner.parentName;
|
|
298
|
+
part.entity = scriptInner.select.entity;
|
|
299
|
+
part.expr = scriptInner.select.expr;
|
|
300
|
+
part.selectFields = scriptInner.select.selectFields;
|
|
301
|
+
part[scriptInner.parentName] = scriptInner.select[scriptInner.parentName];
|
|
302
|
+
}
|
|
219
303
|
|
|
220
|
-
|
|
221
|
-
|
|
304
|
+
// will search multiple values in a field
|
|
305
|
+
if(part.name === "any"){
|
|
306
|
+
// var members = data.memberContext.Member.where(r => r.first_name.any($$), "Rich, james, Oliver" ).toList();
|
|
307
|
+
var expre = this.findExpression(part.parentFeild, cachedExpr.query.expressions)
|
|
308
|
+
expre.func = "IN";
|
|
309
|
+
expre.arg = `(${part.query})`;
|
|
310
|
+
expre.isFunction = true;
|
|
311
|
+
}
|
|
222
312
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
var
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (func == "==" || func == "===") {
|
|
239
|
-
func = "=";
|
|
240
|
-
}
|
|
241
|
-
else if (func == "!==") {
|
|
242
|
-
func = "!=";
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
arg = match[2] || match[4];
|
|
246
|
-
if (arg == "true" || arg == "false") {
|
|
247
|
-
arg = arg == "true";
|
|
248
|
-
}
|
|
249
|
-
else if (arg && arg.charAt(0) == arg.charAt(arg.length - 1) && (arg.charAt(0) == "'" || arg.charAt(0) == '"')) {
|
|
250
|
-
arg = arg.slice(1, -1);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
part.entity = entity;
|
|
254
|
-
if(this.isFunction(part.name)){
|
|
255
|
-
var scriptInner = {
|
|
256
|
-
include : [],
|
|
257
|
-
entityMap : entityMap
|
|
258
|
-
};
|
|
259
|
-
this.buildScript(part.inside, part.name, scriptInner, parentField, true);
|
|
260
|
-
parts.parentName = scriptInner.parentName;
|
|
261
|
-
part[scriptInner.parentName] = {};
|
|
262
|
-
if(part.name === "where"){
|
|
263
|
-
part.parentName = scriptInner.parentName;
|
|
264
|
-
part.entity = scriptInner.where.entity;
|
|
265
|
-
part.expr = scriptInner.where.expr;
|
|
266
|
-
part.selectFields = scriptInner.where.selectFields;
|
|
267
|
-
part[scriptInner.parentName] = scriptInner.where[scriptInner.parentName];
|
|
268
|
-
}
|
|
269
|
-
if(part.name === "include"){
|
|
270
|
-
part.parentName = scriptInner.parentName;
|
|
271
|
-
part.entity = scriptInner.include.entity;
|
|
272
|
-
part.expr = scriptInner.include.expr;
|
|
273
|
-
part.selectFields = scriptInner.include.selectFields;
|
|
274
|
-
part[scriptInner.parentName] = scriptInner.include[scriptInner.parentName];
|
|
313
|
+
if(part.name === "like"){
|
|
314
|
+
// var members = data.memberContext.Member.where(r => r.space_id == $$ && r.user_id != null && r.first_name.like($$),data.params.query.id, "r" ).toList();
|
|
315
|
+
var expre = this.findExpression(part.parentFeild, cachedExpr.query.expressions)
|
|
316
|
+
expre.func = part.name;
|
|
317
|
+
expre.arg = part.query;
|
|
318
|
+
expre.isFunction = true;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
}
|
|
322
|
+
else{
|
|
323
|
+
throw "Cannot have inner functions unless its a Where, Include, Select or Like caluse"
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
275
327
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
describeExpressionParts(parts) {
|
|
331
|
+
if(parts.query) {
|
|
332
|
+
let match, fields, func, arg;
|
|
333
|
+
var part = {};
|
|
334
|
+
part.inside = parts.query.query;
|
|
335
|
+
part.expressions = [];
|
|
336
|
+
var partQuery = part.inside;
|
|
337
|
+
var entity = this.getEntity(partQuery);
|
|
338
|
+
var exprPartRegExp = this.OPERATORS_REGEX(entity);
|
|
339
|
+
// check if query contains an AND.
|
|
340
|
+
var splitByAnd = partQuery.split("and");
|
|
341
|
+
for (let splitAnds in splitByAnd) {
|
|
342
|
+
|
|
343
|
+
if (match = splitByAnd[splitAnds].match(exprPartRegExp)) {
|
|
344
|
+
fields = match[1].split(".");
|
|
345
|
+
func = (match[2] ? fields[fields.length - 1] : (match[3] || "exists"));
|
|
296
346
|
|
|
347
|
+
if (func == "==" || func == "===") {
|
|
348
|
+
func = "=";
|
|
349
|
+
}
|
|
350
|
+
else if (func == "!==") {
|
|
351
|
+
func = "!=";
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
arg = match[2] || match[4];
|
|
355
|
+
if (arg == "true" || arg == "false") {
|
|
356
|
+
arg = arg == "true";
|
|
357
|
+
}
|
|
358
|
+
else if (arg && arg.charAt(0) == arg.charAt(arg.length - 1) && (arg.charAt(0) == "'" || arg.charAt(0) == '"')) {
|
|
359
|
+
arg = arg.slice(1, -1);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
part.entity = entity;
|
|
363
|
+
|
|
364
|
+
part.expressions.push({
|
|
365
|
+
field: fields[0],
|
|
366
|
+
func : func.toLowerCase(),
|
|
367
|
+
arg : arg
|
|
368
|
+
});
|
|
369
|
+
parts.query = part;
|
|
297
370
|
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
298
373
|
|
|
299
374
|
return parts;
|
|
300
375
|
}
|
|
@@ -339,7 +414,7 @@ class queryScript{
|
|
|
339
414
|
}
|
|
340
415
|
|
|
341
416
|
isFunction(func){
|
|
342
|
-
var funcList = ["
|
|
417
|
+
var funcList = [ "include", "like", "any"]
|
|
343
418
|
for(var i =0; i < funcList.length; i++){
|
|
344
419
|
if(funcList[i] === func){
|
|
345
420
|
return true
|
package/SQLLiteEngine.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Version 0.0.
|
|
1
|
+
// Version 0.0.8
|
|
2
2
|
var tools = require('masterrecord/Tools');
|
|
3
3
|
|
|
4
4
|
class SQLLiteEngine {
|
|
@@ -260,41 +260,48 @@ class SQLLiteEngine {
|
|
|
260
260
|
var $that = this;
|
|
261
261
|
if(whereEntity){
|
|
262
262
|
var entity = this.getEntity(query.parentName, query.entityMap);
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
263
|
+
|
|
264
|
+
var item = whereEntity[query.parentName].query;
|
|
265
|
+
for (let exp in item.expressions) {
|
|
266
|
+
var field = tools.capitalizeFirstLetter(item.expressions[exp].field);
|
|
267
|
+
if(mainQuery[field]){
|
|
268
|
+
if(mainQuery[field].isNavigational){
|
|
269
|
+
entity = $that.getEntity(field, query.entityMap);
|
|
270
|
+
field = item.fields[1];
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if(item.expressions[exp].arg === "null"){
|
|
274
|
+
if(item.expressions[exp].func === "="){
|
|
275
|
+
item.expressions[exp].func = "is"
|
|
276
|
+
}
|
|
277
|
+
if(item.expressions[exp].func === "!="){
|
|
278
|
+
item.expressions[exp].func = "is not"
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if(strQuery === ""){
|
|
282
|
+
if(item.expressions[exp].arg === "null"){
|
|
283
|
+
strQuery = `WHERE ${entity}.${field} ${item.expressions[exp].func} ${item.expressions[exp].arg}`;
|
|
284
|
+
}else{
|
|
285
|
+
if(item.expressions[exp].func === "IN"){
|
|
286
|
+
strQuery = `WHERE ${entity}.${field} ${item.expressions[exp].func} ${item.expressions[exp].arg}`;
|
|
287
287
|
}
|
|
288
288
|
else{
|
|
289
|
-
|
|
290
|
-
strQuery = `${strQuery} and ${entity}.${field} ${item.expressions[exp].func} ${item.expressions[exp].arg}`;
|
|
291
|
-
}else{
|
|
292
|
-
strQuery = `${strQuery} and ${entity}.${field} ${item.expressions[exp].func} '${item.expressions[exp].arg}'`;
|
|
293
|
-
}
|
|
294
|
-
|
|
289
|
+
strQuery = `WHERE ${entity}.${field} ${item.expressions[exp].func} '${item.expressions[exp].arg}'`;
|
|
295
290
|
}
|
|
296
291
|
}
|
|
297
292
|
}
|
|
293
|
+
else{
|
|
294
|
+
if(item.expressions[exp].arg === "null"){
|
|
295
|
+
strQuery = `${strQuery} and ${entity}.${field} ${item.expressions[exp].func} ${item.expressions[exp].arg}`;
|
|
296
|
+
}else{
|
|
297
|
+
strQuery = `${strQuery} and ${entity}.${field} ${item.expressions[exp].func} '${item.expressions[exp].arg}'`;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
298
305
|
}
|
|
299
306
|
return strQuery;
|
|
300
307
|
}
|
package/context.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Version 0.0.5
|
|
2
2
|
|
|
3
|
-
var modelBuilder = require('./Entity/
|
|
3
|
+
var modelBuilder = require('./Entity/EntityModelBuilder');
|
|
4
4
|
var query = require('masterrecord/QueryLanguage/queryMethods');
|
|
5
5
|
var tools = require('./Tools');
|
|
6
6
|
var SQLLiteEngine = require('masterrecord/SQLLiteEngine');
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "masterrecord",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"better-sqlite3": "^
|
|
5
|
-
"commander": "^11.
|
|
6
|
-
"glob" : "^10.3.
|
|
4
|
+
"better-sqlite3": "^9.0.0",
|
|
5
|
+
"commander": "^11.1.0",
|
|
6
|
+
"glob" : "^10.3.10",
|
|
7
7
|
"deep-object-diff" : "^1.1.9"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.39",
|
|
10
10
|
"description": "An Object-relational mapping for the Master framework. Master Record connects classes to relational database tables to establish a database with almost zero-configuration ",
|
|
11
11
|
"homepage": "https://github.com/Tailor/MasterRecord#readme",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "git+https://github.com/Tailor/Masterrecord.git"
|
|
15
15
|
},
|
|
16
|
-
"main": "
|
|
16
|
+
"main": "MasterRecord.js",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
19
19
|
},
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
// // version 0.0.2
|
|
3
|
-
|
|
4
|
-
// class selectManager{
|
|
5
|
-
// constructor( query) {
|
|
6
|
-
|
|
7
|
-
// /*
|
|
8
|
-
// queryObject
|
|
9
|
-
// {
|
|
10
|
-
// "where": where user.id = 1
|
|
11
|
-
// "raw": "select * from tablename where user.id = 2" OR false,
|
|
12
|
-
// "builder": builderObject,
|
|
13
|
-
// "select" : "*",
|
|
14
|
-
// "from" : from tablename
|
|
15
|
-
// }
|
|
16
|
-
// */
|
|
17
|
-
// this._query = query;
|
|
18
|
-
// this._queryBuilder = query.builder;
|
|
19
|
-
// this._context = query.builder.__context;
|
|
20
|
-
// }
|
|
21
|
-
|
|
22
|
-
// single(){
|
|
23
|
-
// var entityValue = this._context._SQLEngine.get(this._query.getScript());
|
|
24
|
-
// var sing = this._queryBuilder.__execute(entityValue, this._queryBuilder);
|
|
25
|
-
// return sing;
|
|
26
|
-
// }
|
|
27
|
-
|
|
28
|
-
// //
|
|
29
|
-
// select(query){
|
|
30
|
-
// // this will come after the where
|
|
31
|
-
// this._query.select = "select " + query;
|
|
32
|
-
// return this;
|
|
33
|
-
// }
|
|
34
|
-
|
|
35
|
-
// count(){
|
|
36
|
-
// // trying to match string select and relace with select Count(*);
|
|
37
|
-
// var res = this._query.select.replace("select *", "select Count(*)");
|
|
38
|
-
// var entityValue = this._context._SQLEngine.get(res);
|
|
39
|
-
// var val = entityValue[Object.keys(entityValue)[0]];
|
|
40
|
-
// return val;
|
|
41
|
-
// }
|
|
42
|
-
|
|
43
|
-
// toList(){
|
|
44
|
-
// var entityValue = this._context._SQLEngine.all(this._query);
|
|
45
|
-
// var toLi = this._queryBuilder.__executeList(entityValue, this._queryBuilder);
|
|
46
|
-
// return toLi;
|
|
47
|
-
// }
|
|
48
|
-
|
|
49
|
-
// }
|
|
50
|
-
|
|
51
|
-
// module.exports = selectManager;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
/*
|
|
55
|
-
|
|
56
|
-
LINQ Extension Methods
|
|
57
|
-
First()
|
|
58
|
-
FirstOrDefault()
|
|
59
|
-
SingleOrDefault()
|
|
60
|
-
Count()
|
|
61
|
-
Min()
|
|
62
|
-
Max()
|
|
63
|
-
Last()
|
|
64
|
-
LastOrDefault()
|
|
65
|
-
Average()
|
|
66
|
-
*/
|