blob: aa0fcd0fbc1fb9caceccc07407a35520ec9241a1 [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.com4a5dfe12013-07-05 07:10:00 -070029 var m = mode;
genia.likes.science@gmail.com78593d72013-07-02 06:33:39 -070030 var query = "use dataverse " + this._properties["dataverse"] + ";\n" + statements.join("\n");
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -070031
genia.likes.science@gmail.com3395d5b2013-07-05 00:47:11 -070032 this._api(
33 {
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -070034 "query" : query,
genia.likes.science@gmail.com4a5dfe12013-07-05 07:10:00 -070035 "mode" : m
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -070036 },
genia.likes.science@gmail.com3395d5b2013-07-05 00:47:11 -070037 successFn,
38 "http://localhost:19002/query"
39 );
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -070040
41 return this;
42};
43
44
genia.likes.science@gmail.com4a5dfe12013-07-05 07:10:00 -070045AsterixDBConnection.prototype.query_status = function(data, successFn) {
46
47 this._api(
48 data,
49 successFn,
50 "http://localhost:19002/query/status"
51 );
52
53 return this;
54};
55
56
57AsterixDBConnection.prototype.query_result = function(data, successFn) {
58 this._api(
59 data,
60 successFn,
61 "http://localhost:19002/query/result"
62 );
63
64 return this;
65};
66
genia.likes.science@gmail.com6686c452013-07-05 08:39:35 -070067
68AsterixDBConnection.prototype.ddl = function(statements, successFn) {
69 if ( typeof statements === 'string') {
70 statements = [ statements ];
71 }
72
73 this._api(
74 {
75 "ddl" : "use dataverse " + this._properties["dataverse"] + ";\n" + statements.join("\n")
76 },
77 successFn,
78 "http://localhost:19002/ddl"
79 );
80}
81
82
83AsterixDBConnection.prototype.update = function(statements, successFn) {
84 if ( typeof statements === 'string') {
85 statements = [ statements ];
86 }
87
88 this._api(
89 {
90 "statements" : "use dataverse " + this._properties["dataverse"] + ";\n" + statements.join("\n")
91 },
92 successFn,
93 "http://localhost:19002/update"
94 );
95}
96
97
genia.likes.science@gmail.com3395d5b2013-07-05 00:47:11 -070098AsterixDBConnection.prototype._api = function(json, onSuccess, endpoint) {
99 var success_fn = onSuccess;
100
101 $.ajax({
102 type: 'GET',
103 url: endpoint,
104 data : json,
105 dataType: "json",
106 success: function(data) {
107 success_fn(data);
108 }
109 // TODO error:
110 });
111
112 return this;
113};
114
115
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -0700116// Asterix Expressions
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700117function AExpression () {
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700118 this._properties = {};
119 this._success = function() {};
120
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700121 return this;
122}
123
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700124
125AExpression.prototype.bind = function(options) {
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700126 var options = options || {};
127
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700128 if (options.hasOwnProperty("success")) {
129 this._success = options["success"];
130 }
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700131
132 if (options.hasOwnProperty("return")) {
133 this._properties["return"] = " return " + options["return"].val();
134 }
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700135};
136
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700137
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700138AExpression.prototype.run = function(successFn) {
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700139 return this;
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700140};
141
142
143AExpression.prototype.val = function() {
144
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700145 var value = "";
146
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700147 // If there is a dataverse defined, provide it.
148 if (this._properties.hasOwnProperty("dataverse")) {
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700149 value += "use dataverse " + this._properties["dataverse"] + ";\n";
150 };
151
152 if (this._properties.hasOwnProperty("value")) {
153 value += this._properties["value"];
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700154 }
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700155
156 return value;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700157};
158
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700159// @param expressionValue [String]
160AExpression.prototype.set = function(expressionValue) {
161 this._properties["value"] = expressionValue;
162 return this;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700163};
164
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700165
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700166// FunctionExpression
167// Parent: AsterixExpression
168//
169// @param options [Various],
170// @key function [String], a function to be applid to the expression
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700171// @key expression [AsterixExpression or AQLClause] an AsterixExpression/Clause to which the fn will be applied
172function FunctionExpression() {
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700173
174 // Initialize superclass
175 AExpression.call(this);
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700176
177 this._properties["function"] = "";
178 this._properties["expression"] = new AExpression().set("");
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700179
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700180 // Check for fn/expression input
181 if (arguments.length == 2 && typeof arguments[0] == "string" &&
182 (arguments[1] instanceof AExpression || arguments[1] instanceof AQLClause)) {
183
184 this._properties["function"] = arguments[0];
185 this._properties["expression"] = arguments[1];
186
187 }
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700188
189 // Return object
190 return this;
191}
192
193
194FunctionExpression.prototype = Object.create(AExpression.prototype);
195FunctionExpression.prototype.constructor = FunctionExpression;
196
197
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700198FunctionExpression.prototype.fn = function(fnName) {
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700199
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700200 if (typeof fnName == "string") {
201 this._properties["function"] = fnName;
202 }
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700203
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700204 return this;
205};
206
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700207
208FunctionExpression.prototype.expression = function(expression) {
209 if (expression instanceof AExpression || expression instanceof AQLClause) {
210 this._properties["expression"] = expression;
211 }
212
213 return this;
214};
215
216
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700217FunctionExpression.prototype.val = function () {
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700218 return this._properties["function"] + "(" + this._properties["expression"].val() + ")";
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700219};
220
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700221
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700222// FLWOGRExpression
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700223//
224// FLWOGRExpression ::= ( ForClause | LetClause ) ( Clause )* "return" Expression
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700225function FLWOGRExpression (options) {
226 // Initialize superclass
227 AExpression.call(this);
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700228
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700229 this._properties["clauses"] = [];
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700230 this._properties["minSize"] = 0;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700231
232 // Bind options and return
233 this.bind(options);
234 return this;
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700235}
236
237
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700238FLWOGRExpression.prototype = Object.create(AExpression.prototype);
239FLWOGRExpression.prototype.constructor = FLWOGRExpression;
240
241
242FLWOGRExpression.prototype.bind = function(options) {
243 AExpression.prototype.bind.call(this, options);
244
245 var options = options || {};
246
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700247 if (options instanceof SetStatement) {
248 this._properties["clauses"].push(options);
249 this._properties["minSize"] += 1;
250 }
251
252 if (this._properties["clauses"].length <= this._properties["minSize"]) {
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700253 // Needs to start with for or let clause
254 if (options instanceof ForClause || options instanceof LetClause) {
255 this._properties["clauses"].push(options);
256 }
257 } else {
258 if (options instanceof AQLClause) {
259 this._properties["clauses"].push(options);
260 }
261 }
262
263 return this;
264};
265
266
267FLWOGRExpression.prototype.val = function() {
268 var value = AExpression.prototype.val.call(this);
269
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700270 var clauseValues = [];
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700271 for (var c in this._properties["clauses"]) {
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700272 clauseValues.push(this._properties["clauses"][c].val());
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700273 }
274
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700275 return value + clauseValues.join("\n");// + ";";
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700276};
277
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700278
genia.likes.science@gmail.com5f425342013-06-13 13:51:26 -0700279FLWOGRExpression.prototype.ReturnClause = function(expression) {
280 return this.bind(new ReturnClause(expression));
281};
282
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700283// AQLClause
284//
285// Base Clause ::= ForClause | LetClause | WhereClause | OrderbyClause | GroupClause | LimitClause | DistinctClause
286function AQLClause() {
287 this._properties = {};
288 this._properties["clause"] = "";
289}
290
291AQLClause.prototype.val = function() {
292 var value = this._properties["clause"];
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700293
294 return value;
295};
296
297AQLClause.prototype.bind = function(options) {
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700298
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700299 if (options instanceof AQLClause) {
300 this._properties["clause"] += " " + options.val();
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700301 }
302
303 return this;
304};
305
genia.likes.science@gmail.com39578302013-05-31 04:42:26 -0700306AQLClause.prototype.set = function(value) {
307 this._properties["clause"] = value;
308 return this;
309};
310
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700311
312// ForClause
313//
314// Grammar:
315// "for" Variable ( "at" Variable )? "in" ( Expression )
316//
317// @param for_variable [String], REQUIRED, first variable in clause
318// @param at_variable [String], NOT REQUIRED, first variable in clause
319// @param expression [AsterixExpression], REQUIRED, expression to evaluate
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700320function ForClause(for_variable, at_variable, expression) {
321 AQLClause.call(this);
322
genia.likes.science@gmail.com78593d72013-07-02 06:33:39 -0700323 this._properties["clause"] = "for " + arguments[0];
genia.likes.science@gmail.comf8cca192013-06-13 15:45:53 -0700324
325 if (arguments.length == 3) {
genia.likes.science@gmail.com78593d72013-07-02 06:33:39 -0700326 this._properties["clause"] += " at " + arguments[1];
genia.likes.science@gmail.comf8cca192013-06-13 15:45:53 -0700327 this._properties["clause"] += " in " + arguments[2].val();
328 } else if (arguments.length == 2) {
329 this._properties["clause"] += " in " + arguments[1].val();
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700330 }
genia.likes.science@gmail.comf8cca192013-06-13 15:45:53 -0700331
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700332 return this;
333}
334
335ForClause.prototype = Object.create(AQLClause.prototype);
336ForClause.prototype.constructor = ForClause;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700337
338
339// LetClause
340//
341// Grammar:
342// LetClause ::= "let" Variable ":=" Expression
343//
344// @param let_variable [String]
345// @param expression [AExpression]
346//
347// TODO Vigorous error checking
348function LetClause(let_variable, expression) {
349 AQLClause.call(this);
350
genia.likes.science@gmail.com78593d72013-07-02 06:33:39 -0700351 this._properties["clause"] = "let " + let_variable + " := ";
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700352 this._properties["clause"] += expression.val();
353
354 return this;
355}
356
357LetClause.prototype = Object.create(AQLClause.prototype);
358LetClause.prototype.constructor = LetClause;
359
360
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700361// ReturnClause
362//
363// Grammar:
364// return [AQLExpression]
365function ReturnClause(expression) {
366 AQLClause.call(this);
367
368 this._properties["clause"] = "return ";
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700369
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700370 if (expression instanceof AExpression || expression instanceof AQLClause) {
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700371 this._properties["clause"] += expression.val();
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700372
373 } else if ( typeof expression == "object" && Object.getPrototypeOf( expression ) === Object.prototype ) {
374
375 // TODO Null object check
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700376
377 this._properties["clause"] += "{";
378 var returnStatements = [];
379 for (returnValue in expression) {
380
381 if (expression[returnValue] instanceof AExpression) {
genia.likes.science@gmail.comfba7cc82013-05-31 04:04:08 -0700382 returnStatements.push('"' + returnValue + '" ' + " : " + expression[returnValue].val());
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700383 } else if (typeof expression[returnValue] == "string") {
genia.likes.science@gmail.comfba7cc82013-05-31 04:04:08 -0700384 returnStatements.push('"' + returnValue + '" ' + " : " + expression[returnValue]);
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700385 }
386 }
387 this._properties["clause"] += returnStatements.join(",\n");
genia.likes.science@gmail.comf7929d82013-06-12 11:30:01 -0700388 this._properties["clause"] += "\n}";
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700389
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700390 } else {
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700391 this._properties["clause"] += new AQLClause().set(expression).val();
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700392 }
393
394 return this;
395}
396
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700397
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700398ReturnClause.prototype = Object.create(AQLClause.prototype);
399ReturnClause.prototype.constructor = ReturnClause;
400
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700401
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700402// WhereClause
403//
404// Grammar:
405// ::= "where" Expression
406//
407// @param expression [BooleanExpression], pushes this expression onto the stack
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700408function WhereClause(expression) {
409 AQLClause.call(this);
410
411 this._properties["stack"] = [];
412
413 this.bind(expression);
414
415 return this;
416}
417
418
419WhereClause.prototype = Object.create(AQLClause.prototype);
420WhereClause.prototype.constructor = WhereClause;
421
422
423WhereClause.prototype.bind = function(expression) {
genia.likes.science@gmail.com64ca88e2013-05-31 10:40:39 -0700424 if (expression instanceof AExpression) {
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700425 this._properties["stack"].push(expression);
426 }
427};
428
429
430WhereClause.prototype.val = function() {
431 var value = "where ";
432
433 var count = this._properties["stack"].length - 1;
434 while (count >= 0) {
435 value += this._properties["stack"][count].val() + " ";
436 count -= 1;
437 }
438
439 return value;
genia.likes.science@gmail.com64ca88e2013-05-31 10:40:39 -0700440};
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700441
442
genia.likes.science@gmail.comd2f753e2013-06-12 13:51:03 -0700443WhereClause.prototype.and = function() {
444
445 var andClauses = [];
446 for (var expression in arguments) {
447
448 if (arguments[expression] instanceof AExpression) {
449 andClauses.push(arguments[expression].val());
450 }
451 }
452
453 if (andClauses.length > 0) {
454 this._properties["stack"].push(new AExpression().set(andClauses.join(" and ")));
455 }
456
457 return this;
458};
459
460
461WhereClause.prototype.or = function() {
462 var orClauses = [];
463 for (var expression in arguments) {
464
465 if (arguments[expression] instanceof AExpression) {
466 orClauses.push(arguments[expression].val());
467 }
468 }
469
470 if (andClauses.length > 0) {
471 this._properties["stack"].push(new AExpression().set(orClauses.join(" and ")));
472 }
473
474 return this;
475};
476
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700477// LimitClause
478// Grammar:
479// LimitClause ::= "limit" Expression ( "offset" Expression )?
480//
481// @param limitExpression [REQUIRED, AQLExpression]
482// @param offsetExpression [OPTIONAL, AQLExpression]
483function LimitClause(limitExpression, offsetExpression) {
484
485 AQLClause.call(this);
486
487 // limitExpression required
488 this._properties["clause"] = "limit " + limitExpression.val();
489
490 // Optional: Offset
491 var offset = typeof offsetExpression ? offsetExpression : null;
492 if (offset != null) {
493 this._properties["clause"] += " offset " + offsetExpression.val();
494 }
495
496 return this;
497}
498
499LimitClause.prototype = Object.create(AQLClause.prototype);
500LimitClause.prototype.constructor = LimitClause;
501
502
503// OrderbyClause
504//
505// Grammar:
506// OrderbyClause ::= "order" "by" Expression ( ( "asc" ) | ( "desc" ) )? ( "," Expression ( ( "asc" ) | ( "desc" ) )? )*
507//
508// @params AQLExpressions and asc/desc strings, in any quantity. At least one required.
509function OrderbyClause() {
510
511 AQLClause.call(this);
512
513 // At least one argument expression is required, and first should be expression
514 if (arguments.length == 0 || !(arguments[0] instanceof AExpression)) {
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700515
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700516 // TODO Not sure which error to throw for an empty OrderBy but this should fail.
517 alert("Order By Error");
518 this._properties["clause"] = null;
519 return this;
520 }
521
522 var expc = 0;
523 var expressions = [];
524
525 while (expc < arguments.length) {
526
527 var expression = "";
528
529 if (arguments[expc] instanceof AExpression) {
530 expression += arguments[expc].val();
531 }
532
533 var next = expc + 1;
534 if (next < arguments.length && (arguments[next] == "asc" || arguments[next] == "desc")) {
535 expc++;
536 expression += " " + arguments[expc];
537 }
538
539 expressions.push(expression);
540
541 expc++;
542 }
543
544 this._properties["clause"] = "order by " + expressions.join(", ");
545 return this;
546}
547
548OrderbyClause.prototype = Object.create(AQLClause.prototype);
549OrderbyClause.prototype.constructor = OrderbyClause;
550
551
genia.likes.science@gmail.com6e392912013-05-31 03:46:59 -0700552// GroupClause
553//
554// Grammar:
555// GroupClause ::= "group" "by" ( Variable ":=" )? Expression ( "," ( Variable ":=" )? Expression )* ( "decor" Variable ":=" Expression ( "," "decor" Variable ":=" Expression )* )? "with" VariableRef ( "," VariableRef )*
556function GroupClause() {
557 AQLClause.call(this);
558
559 if (arguments.length == 0) {
560 // TODO Not sure which error to throw for an empty GroupBy but this should fail.
561 alert("Group Error");
562 this._properties["clause"] = null;
563 return this;
564 }
565
566 var expc = 0;
567 var expressions = [];
568 var variableRefs = [];
569 var isDecor = false;
genia.likes.science@gmail.com5f425342013-06-13 13:51:26 -0700570
genia.likes.science@gmail.com6e392912013-05-31 03:46:59 -0700571 while (expc < arguments.length) {
572
573 if (arguments[expc] instanceof AExpression) {
574
575 isDecor = false;
576 expressions.push(arguments[expc].val());
577
578 } else if (typeof arguments[expc] == "string") {
579
580 // Special keywords, decor & with
581 if (arguments[expc] == "decor") {
582 isDecor = true;
583 } else if (arguments[expc] == "with") {
584 isDecor = false;
585 expc++;
586 while (expc < arguments.length) {
587 variableRefs.push("$" + arguments[expc]);
588 expc++;
589 }
590
591 // Variables and variable refs
592 } else {
593
594 var nextc = expc + 1;
595 var expression = "";
596
597 if (isDecor) {
598 expression += "decor ";
599 isDecor = false;
600 }
601
602 expression += "$" + arguments[expc] + " := " + arguments[nextc].val();
603 expressions.push(expression);
604 expc++;
605 }
606 }
607
608 expc++;
609 }
610
611 this._properties["clause"] = "group by " + expressions.join(", ") + " with " + variableRefs.join(", ");
612 return this;
613}
614
615GroupClause.prototype = Object.create(AQLClause.prototype);
616GroupClause.prototype.constructor = GroupClause;
617
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700618
619// SetStatement
620//
621// Grammar
622// "set" Identifier StringLiteral
623function SetStatement (identifier, stringLiteral) {
624 AExpression.call(this);
625
626 var statement = "set " + identifier + ' "' + stringLiteral + '";';
627
628 AExpression.prototype.set.call(this, statement);
629
630 return this;
631}
632
633SetStatement.prototype = Object.create(AExpression.prototype);
634SetStatement.prototype.constructor = SetStatement;
genia.likes.science@gmail.come34c57b2013-05-31 10:15:49 -0700635
636
637// Quantified Expression
638//
639// Grammar
640// QuantifiedExpression ::= ( ( "some" ) | ( "every" ) ) Variable "in" Expression ( "," Variable "in" Expression )* "satisfies" Expression
641//
642// @param String some/every
643// @param [AExpression]
644// @param [Aexpression] satisfiesExpression
645function QuantifiedExpression (keyword, expressions, satisfiesExpression) {
646 AExpression.call(this);
647
648 var expression = keyword + " ";
649 var varsInExpressions = [];
650
651 for (var varInExpression in expressions) {
652 varsInExpressions.push(varInExpression + " in " + expressions[varInExpression].val());
653 }
654 expression += varsInExpressions.join(", ") + " satisfies " + satisfiesExpression.val();
655
656 AExpression.prototype.set.call(this, expression);
657
658 return this;
659}
660
661QuantifiedExpression.prototype = Object.create(AExpression.prototype);
662QuantifiedExpression.prototype.constructor = QuantifiedExpression;
genia.likes.science@gmail.com64ca88e2013-05-31 10:40:39 -0700663
664QuantifiedExpression.prototype.val = function() {
665 var value = AExpression.prototype.val.call(this);
666 return "(" + value + ")";
667};