blob: 6225aa735cc5920a37833e2bd676c0f16f92f29b [file] [log] [blame]
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -07001function AsterixDBConnection(configuration) {
2 this._properties = {};
3 this._properties["dataverse"] = "";
4 this._properties["mode"] = "synchronous";
5
6 var configuration = arguments || {};
7
8 for (var key in configuration) {
9 this._properties[key] = configuration[key];
10 }
11
12 return this;
13}
14
15
16AsterixDBConnection.prototype.dataverse = function(dataverseName) {
17 this._properties["dataverse"] = dataverseName;
18
19 return this;
20};
21
22
genia.likes.science@gmail.com4a5dfe12013-07-05 07:10:00 -070023AsterixDBConnection.prototype.query = function(statements, successFn, mode) {
genia.likes.science@gmail.com3395d5b2013-07-05 00:47:11 -070024
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -070025 if ( typeof statements === 'string') {
26 statements = [ statements ];
27 }
28
genia.likes.science@gmail.com212a6442013-07-13 20:40:11 -070029 var m = typeof mode ? mode : "synchronous";
30
genia.likes.science@gmail.com78593d72013-07-02 06:33:39 -070031 var query = "use dataverse " + this._properties["dataverse"] + ";\n" + statements.join("\n");
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -070032
genia.likes.science@gmail.com3395d5b2013-07-05 00:47:11 -070033 this._api(
34 {
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -070035 "query" : query,
genia.likes.science@gmail.com4a5dfe12013-07-05 07:10:00 -070036 "mode" : m
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -070037 },
genia.likes.science@gmail.com3395d5b2013-07-05 00:47:11 -070038 successFn,
39 "http://localhost:19002/query"
40 );
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -070041
42 return this;
43};
44
45
genia.likes.science@gmail.com4a5dfe12013-07-05 07:10:00 -070046AsterixDBConnection.prototype.query_status = function(data, successFn) {
47
48 this._api(
49 data,
50 successFn,
51 "http://localhost:19002/query/status"
52 );
53
54 return this;
55};
56
57
58AsterixDBConnection.prototype.query_result = function(data, successFn) {
59 this._api(
60 data,
61 successFn,
62 "http://localhost:19002/query/result"
63 );
64
65 return this;
66};
67
genia.likes.science@gmail.com6686c452013-07-05 08:39:35 -070068
69AsterixDBConnection.prototype.ddl = function(statements, successFn) {
70 if ( typeof statements === 'string') {
71 statements = [ statements ];
72 }
73
74 this._api(
75 {
76 "ddl" : "use dataverse " + this._properties["dataverse"] + ";\n" + statements.join("\n")
77 },
78 successFn,
79 "http://localhost:19002/ddl"
80 );
81}
82
83
84AsterixDBConnection.prototype.update = function(statements, successFn) {
85 if ( typeof statements === 'string') {
86 statements = [ statements ];
87 }
88
89 this._api(
90 {
91 "statements" : "use dataverse " + this._properties["dataverse"] + ";\n" + statements.join("\n")
92 },
93 successFn,
94 "http://localhost:19002/update"
95 );
96}
97
98
genia.likes.science@gmail.com3395d5b2013-07-05 00:47:11 -070099AsterixDBConnection.prototype._api = function(json, onSuccess, endpoint) {
100 var success_fn = onSuccess;
101
102 $.ajax({
103 type: 'GET',
104 url: endpoint,
105 data : json,
106 dataType: "json",
107 success: function(data) {
108 success_fn(data);
109 }
110 // TODO error:
111 });
112
113 return this;
114};
115
116
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -0700117// Asterix Expressions
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700118function AExpression () {
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700119 this._properties = {};
120 this._success = function() {};
121
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700122 return this;
123}
124
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700125
126AExpression.prototype.bind = function(options) {
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700127 var options = options || {};
128
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700129 if (options.hasOwnProperty("success")) {
130 this._success = options["success"];
131 }
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700132
133 if (options.hasOwnProperty("return")) {
134 this._properties["return"] = " return " + options["return"].val();
135 }
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700136};
137
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700138
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700139AExpression.prototype.run = function(successFn) {
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700140 return this;
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700141};
142
143
144AExpression.prototype.val = function() {
145
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700146 var value = "";
147
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700148 // If there is a dataverse defined, provide it.
149 if (this._properties.hasOwnProperty("dataverse")) {
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700150 value += "use dataverse " + this._properties["dataverse"] + ";\n";
151 };
152
153 if (this._properties.hasOwnProperty("value")) {
154 value += this._properties["value"];
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700155 }
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700156
157 return value;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700158};
159
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700160// @param expressionValue [String]
161AExpression.prototype.set = function(expressionValue) {
162 this._properties["value"] = expressionValue;
163 return this;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700164};
165
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700166
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700167// FunctionExpression
168// Parent: AsterixExpression
169//
170// @param options [Various],
171// @key function [String], a function to be applid to the expression
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700172// @key expression [AsterixExpression or AQLClause] an AsterixExpression/Clause to which the fn will be applied
173function FunctionExpression() {
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700174
175 // Initialize superclass
176 AExpression.call(this);
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700177
178 this._properties["function"] = "";
179 this._properties["expression"] = new AExpression().set("");
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700180
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700181 // Check for fn/expression input
182 if (arguments.length == 2 && typeof arguments[0] == "string" &&
183 (arguments[1] instanceof AExpression || arguments[1] instanceof AQLClause)) {
184
185 this._properties["function"] = arguments[0];
186 this._properties["expression"] = arguments[1];
187
188 }
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700189
190 // Return object
191 return this;
192}
193
194
195FunctionExpression.prototype = Object.create(AExpression.prototype);
196FunctionExpression.prototype.constructor = FunctionExpression;
197
198
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700199FunctionExpression.prototype.fn = function(fnName) {
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700200
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700201 if (typeof fnName == "string") {
202 this._properties["function"] = fnName;
203 }
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700204
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700205 return this;
206};
207
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700208
209FunctionExpression.prototype.expression = function(expression) {
210 if (expression instanceof AExpression || expression instanceof AQLClause) {
211 this._properties["expression"] = expression;
212 }
213
214 return this;
215};
216
217
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700218FunctionExpression.prototype.val = function () {
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700219 return this._properties["function"] + "(" + this._properties["expression"].val() + ")";
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700220};
221
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700222
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700223// FLWOGRExpression
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700224//
225// FLWOGRExpression ::= ( ForClause | LetClause ) ( Clause )* "return" Expression
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700226function FLWOGRExpression (options) {
227 // Initialize superclass
228 AExpression.call(this);
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700229
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700230 this._properties["clauses"] = [];
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700231 this._properties["minSize"] = 0;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700232
233 // Bind options and return
234 this.bind(options);
235 return this;
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700236}
237
238
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700239FLWOGRExpression.prototype = Object.create(AExpression.prototype);
240FLWOGRExpression.prototype.constructor = FLWOGRExpression;
241
242
243FLWOGRExpression.prototype.bind = function(options) {
244 AExpression.prototype.bind.call(this, options);
245
246 var options = options || {};
247
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700248 if (options instanceof SetStatement) {
249 this._properties["clauses"].push(options);
250 this._properties["minSize"] += 1;
251 }
252
253 if (this._properties["clauses"].length <= this._properties["minSize"]) {
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700254 // Needs to start with for or let clause
255 if (options instanceof ForClause || options instanceof LetClause) {
256 this._properties["clauses"].push(options);
257 }
258 } else {
259 if (options instanceof AQLClause) {
260 this._properties["clauses"].push(options);
261 }
262 }
263
264 return this;
265};
266
267
268FLWOGRExpression.prototype.val = function() {
269 var value = AExpression.prototype.val.call(this);
270
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700271 var clauseValues = [];
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700272 for (var c in this._properties["clauses"]) {
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700273 clauseValues.push(this._properties["clauses"][c].val());
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700274 }
275
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700276 return value + clauseValues.join("\n");// + ";";
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700277};
278
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700279
genia.likes.science@gmail.com5f425342013-06-13 13:51:26 -0700280FLWOGRExpression.prototype.ReturnClause = function(expression) {
281 return this.bind(new ReturnClause(expression));
282};
283
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700284// AQLClause
285//
286// Base Clause ::= ForClause | LetClause | WhereClause | OrderbyClause | GroupClause | LimitClause | DistinctClause
287function AQLClause() {
288 this._properties = {};
289 this._properties["clause"] = "";
290}
291
292AQLClause.prototype.val = function() {
293 var value = this._properties["clause"];
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700294
295 return value;
296};
297
298AQLClause.prototype.bind = function(options) {
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700299
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700300 if (options instanceof AQLClause) {
301 this._properties["clause"] += " " + options.val();
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700302 }
303
304 return this;
305};
306
genia.likes.science@gmail.com39578302013-05-31 04:42:26 -0700307AQLClause.prototype.set = function(value) {
308 this._properties["clause"] = value;
309 return this;
310};
311
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700312
313// ForClause
314//
315// Grammar:
316// "for" Variable ( "at" Variable )? "in" ( Expression )
317//
318// @param for_variable [String], REQUIRED, first variable in clause
319// @param at_variable [String], NOT REQUIRED, first variable in clause
320// @param expression [AsterixExpression], REQUIRED, expression to evaluate
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700321function ForClause(for_variable, at_variable, expression) {
322 AQLClause.call(this);
323
genia.likes.science@gmail.com78593d72013-07-02 06:33:39 -0700324 this._properties["clause"] = "for " + arguments[0];
genia.likes.science@gmail.comf8cca192013-06-13 15:45:53 -0700325
326 if (arguments.length == 3) {
genia.likes.science@gmail.com78593d72013-07-02 06:33:39 -0700327 this._properties["clause"] += " at " + arguments[1];
genia.likes.science@gmail.comf8cca192013-06-13 15:45:53 -0700328 this._properties["clause"] += " in " + arguments[2].val();
329 } else if (arguments.length == 2) {
330 this._properties["clause"] += " in " + arguments[1].val();
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700331 }
genia.likes.science@gmail.comf8cca192013-06-13 15:45:53 -0700332
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700333 return this;
334}
335
336ForClause.prototype = Object.create(AQLClause.prototype);
337ForClause.prototype.constructor = ForClause;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700338
339
340// LetClause
341//
342// Grammar:
343// LetClause ::= "let" Variable ":=" Expression
344//
345// @param let_variable [String]
346// @param expression [AExpression]
347//
348// TODO Vigorous error checking
349function LetClause(let_variable, expression) {
350 AQLClause.call(this);
351
genia.likes.science@gmail.com78593d72013-07-02 06:33:39 -0700352 this._properties["clause"] = "let " + let_variable + " := ";
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700353 this._properties["clause"] += expression.val();
354
355 return this;
356}
357
358LetClause.prototype = Object.create(AQLClause.prototype);
359LetClause.prototype.constructor = LetClause;
360
361
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700362// ReturnClause
363//
364// Grammar:
365// return [AQLExpression]
366function ReturnClause(expression) {
367 AQLClause.call(this);
368
369 this._properties["clause"] = "return ";
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700370
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700371 if (expression instanceof AExpression || expression instanceof AQLClause) {
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700372 this._properties["clause"] += expression.val();
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700373
374 } else if ( typeof expression == "object" && Object.getPrototypeOf( expression ) === Object.prototype ) {
375
376 // TODO Null object check
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700377
378 this._properties["clause"] += "{";
379 var returnStatements = [];
380 for (returnValue in expression) {
381
382 if (expression[returnValue] instanceof AExpression) {
genia.likes.science@gmail.comfba7cc82013-05-31 04:04:08 -0700383 returnStatements.push('"' + returnValue + '" ' + " : " + expression[returnValue].val());
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700384 } else if (typeof expression[returnValue] == "string") {
genia.likes.science@gmail.comfba7cc82013-05-31 04:04:08 -0700385 returnStatements.push('"' + returnValue + '" ' + " : " + expression[returnValue]);
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700386 }
387 }
388 this._properties["clause"] += returnStatements.join(",\n");
genia.likes.science@gmail.comf7929d82013-06-12 11:30:01 -0700389 this._properties["clause"] += "\n}";
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700390
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700391 } else {
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700392 this._properties["clause"] += new AQLClause().set(expression).val();
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700393 }
394
395 return this;
396}
397
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700398
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700399ReturnClause.prototype = Object.create(AQLClause.prototype);
400ReturnClause.prototype.constructor = ReturnClause;
401
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700402
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700403// WhereClause
404//
405// Grammar:
406// ::= "where" Expression
407//
408// @param expression [BooleanExpression], pushes this expression onto the stack
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700409function WhereClause(expression) {
410 AQLClause.call(this);
411
412 this._properties["stack"] = [];
413
414 this.bind(expression);
415
416 return this;
417}
418
419
420WhereClause.prototype = Object.create(AQLClause.prototype);
421WhereClause.prototype.constructor = WhereClause;
422
423
424WhereClause.prototype.bind = function(expression) {
genia.likes.science@gmail.com64ca88e2013-05-31 10:40:39 -0700425 if (expression instanceof AExpression) {
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700426 this._properties["stack"].push(expression);
427 }
428};
429
430
431WhereClause.prototype.val = function() {
432 var value = "where ";
433
434 var count = this._properties["stack"].length - 1;
435 while (count >= 0) {
436 value += this._properties["stack"][count].val() + " ";
437 count -= 1;
438 }
439
440 return value;
genia.likes.science@gmail.com64ca88e2013-05-31 10:40:39 -0700441};
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700442
443
genia.likes.science@gmail.comd2f753e2013-06-12 13:51:03 -0700444WhereClause.prototype.and = function() {
445
446 var andClauses = [];
447 for (var expression in arguments) {
448
449 if (arguments[expression] instanceof AExpression) {
450 andClauses.push(arguments[expression].val());
451 }
452 }
453
454 if (andClauses.length > 0) {
455 this._properties["stack"].push(new AExpression().set(andClauses.join(" and ")));
456 }
457
458 return this;
459};
460
461
462WhereClause.prototype.or = function() {
463 var orClauses = [];
464 for (var expression in arguments) {
465
466 if (arguments[expression] instanceof AExpression) {
467 orClauses.push(arguments[expression].val());
468 }
469 }
470
471 if (andClauses.length > 0) {
472 this._properties["stack"].push(new AExpression().set(orClauses.join(" and ")));
473 }
474
475 return this;
476};
477
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700478// LimitClause
479// Grammar:
480// LimitClause ::= "limit" Expression ( "offset" Expression )?
481//
482// @param limitExpression [REQUIRED, AQLExpression]
483// @param offsetExpression [OPTIONAL, AQLExpression]
484function LimitClause(limitExpression, offsetExpression) {
485
486 AQLClause.call(this);
487
488 // limitExpression required
489 this._properties["clause"] = "limit " + limitExpression.val();
490
491 // Optional: Offset
492 var offset = typeof offsetExpression ? offsetExpression : null;
493 if (offset != null) {
494 this._properties["clause"] += " offset " + offsetExpression.val();
495 }
496
497 return this;
498}
499
500LimitClause.prototype = Object.create(AQLClause.prototype);
501LimitClause.prototype.constructor = LimitClause;
502
503
504// OrderbyClause
505//
506// Grammar:
507// OrderbyClause ::= "order" "by" Expression ( ( "asc" ) | ( "desc" ) )? ( "," Expression ( ( "asc" ) | ( "desc" ) )? )*
508//
509// @params AQLExpressions and asc/desc strings, in any quantity. At least one required.
510function OrderbyClause() {
511
512 AQLClause.call(this);
513
514 // At least one argument expression is required, and first should be expression
515 if (arguments.length == 0 || !(arguments[0] instanceof AExpression)) {
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700516
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700517 // TODO Not sure which error to throw for an empty OrderBy but this should fail.
518 alert("Order By Error");
519 this._properties["clause"] = null;
520 return this;
521 }
522
523 var expc = 0;
524 var expressions = [];
525
526 while (expc < arguments.length) {
527
528 var expression = "";
529
530 if (arguments[expc] instanceof AExpression) {
531 expression += arguments[expc].val();
532 }
533
534 var next = expc + 1;
535 if (next < arguments.length && (arguments[next] == "asc" || arguments[next] == "desc")) {
536 expc++;
537 expression += " " + arguments[expc];
538 }
539
540 expressions.push(expression);
541
542 expc++;
543 }
544
545 this._properties["clause"] = "order by " + expressions.join(", ");
546 return this;
547}
548
549OrderbyClause.prototype = Object.create(AQLClause.prototype);
550OrderbyClause.prototype.constructor = OrderbyClause;
551
552
genia.likes.science@gmail.com6e392912013-05-31 03:46:59 -0700553// GroupClause
554//
555// Grammar:
556// GroupClause ::= "group" "by" ( Variable ":=" )? Expression ( "," ( Variable ":=" )? Expression )* ( "decor" Variable ":=" Expression ( "," "decor" Variable ":=" Expression )* )? "with" VariableRef ( "," VariableRef )*
557function GroupClause() {
558 AQLClause.call(this);
559
560 if (arguments.length == 0) {
561 // TODO Not sure which error to throw for an empty GroupBy but this should fail.
562 alert("Group Error");
563 this._properties["clause"] = null;
564 return this;
565 }
566
567 var expc = 0;
568 var expressions = [];
569 var variableRefs = [];
570 var isDecor = false;
genia.likes.science@gmail.com5f425342013-06-13 13:51:26 -0700571
genia.likes.science@gmail.com6e392912013-05-31 03:46:59 -0700572 while (expc < arguments.length) {
573
574 if (arguments[expc] instanceof AExpression) {
575
576 isDecor = false;
577 expressions.push(arguments[expc].val());
578
579 } else if (typeof arguments[expc] == "string") {
580
581 // Special keywords, decor & with
582 if (arguments[expc] == "decor") {
583 isDecor = true;
584 } else if (arguments[expc] == "with") {
585 isDecor = false;
586 expc++;
587 while (expc < arguments.length) {
genia.likes.science@gmail.com212a6442013-07-13 20:40:11 -0700588 variableRefs.push(arguments[expc]);
genia.likes.science@gmail.com6e392912013-05-31 03:46:59 -0700589 expc++;
590 }
591
592 // Variables and variable refs
593 } else {
594
595 var nextc = expc + 1;
596 var expression = "";
597
598 if (isDecor) {
599 expression += "decor ";
600 isDecor = false;
601 }
602
genia.likes.science@gmail.com212a6442013-07-13 20:40:11 -0700603 expression += arguments[expc] + " := " + arguments[nextc].val();
genia.likes.science@gmail.com6e392912013-05-31 03:46:59 -0700604 expressions.push(expression);
605 expc++;
606 }
607 }
608
609 expc++;
610 }
611
612 this._properties["clause"] = "group by " + expressions.join(", ") + " with " + variableRefs.join(", ");
613 return this;
614}
615
616GroupClause.prototype = Object.create(AQLClause.prototype);
617GroupClause.prototype.constructor = GroupClause;
618
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700619
620// SetStatement
621//
622// Grammar
623// "set" Identifier StringLiteral
624function SetStatement (identifier, stringLiteral) {
625 AExpression.call(this);
626
627 var statement = "set " + identifier + ' "' + stringLiteral + '";';
628
629 AExpression.prototype.set.call(this, statement);
630
631 return this;
632}
633
634SetStatement.prototype = Object.create(AExpression.prototype);
635SetStatement.prototype.constructor = SetStatement;
genia.likes.science@gmail.come34c57b2013-05-31 10:15:49 -0700636
637
638// Quantified Expression
639//
640// Grammar
641// QuantifiedExpression ::= ( ( "some" ) | ( "every" ) ) Variable "in" Expression ( "," Variable "in" Expression )* "satisfies" Expression
642//
643// @param String some/every
644// @param [AExpression]
645// @param [Aexpression] satisfiesExpression
646function QuantifiedExpression (keyword, expressions, satisfiesExpression) {
647 AExpression.call(this);
648
649 var expression = keyword + " ";
650 var varsInExpressions = [];
651
652 for (var varInExpression in expressions) {
653 varsInExpressions.push(varInExpression + " in " + expressions[varInExpression].val());
654 }
655 expression += varsInExpressions.join(", ") + " satisfies " + satisfiesExpression.val();
656
657 AExpression.prototype.set.call(this, expression);
658
659 return this;
660}
661
662QuantifiedExpression.prototype = Object.create(AExpression.prototype);
663QuantifiedExpression.prototype.constructor = QuantifiedExpression;
genia.likes.science@gmail.com64ca88e2013-05-31 10:40:39 -0700664
665QuantifiedExpression.prototype.val = function() {
666 var value = AExpression.prototype.val.call(this);
667 return "(" + value + ")";
668};