blob: bb7bc5f03a82a893c8b4a78f1e04f5adef8bcf75 [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
23AsterixDBConnection.prototype.run = function(statements, successFn) {
24
25 var success_fn = successFn;
26
27 if ( typeof statements === 'string') {
28 statements = [ statements ];
29 }
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 var mode = this._properties["mode"];
33
34 $.ajax({
35 type : 'GET',
36 url : "http://localhost:19002/query",
37 data : {
38 "query" : query,
39 "mode" : mode
40 },
41 dataType : "json",
42 success : function(data) {
43 success_fn(data);
44 },
45 error: function(r) {
genia.likes.science@gmail.comf8cca192013-06-13 15:45:53 -070046 //alert("AsterixSDK ERROR\n" + JSON.stringify(r));
genia.likes.science@gmail.comb91b577a2013-06-13 14:36:06 -070047 }
48 });
49
50 return this;
51};
52
53
54// Asterix Expressions
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -070055function AExpression () {
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070056 this._properties = {};
57 this._success = function() {};
58
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070059 return this;
60}
61
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -070062
63AExpression.prototype.bind = function(options) {
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070064 var options = options || {};
65
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070066 if (options.hasOwnProperty("success")) {
67 this._success = options["success"];
68 }
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -070069
70 if (options.hasOwnProperty("return")) {
71 this._properties["return"] = " return " + options["return"].val();
72 }
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070073};
74
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070075
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -070076AExpression.prototype.run = function(successFn) {
77 var success_fn = successFn;
genia.likes.science@gmail.com5a7c2d72013-06-06 00:54:28 -070078
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070079 $.ajax({
80 type : 'GET',
genia.likes.science@gmail.comfc5f5092013-06-12 00:49:46 -070081 url : "http://localhost:19002/query",
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -070082 data : {"query" : "use dataverse TinySocial;\n" + this.val()},
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -070083 dataType : "json",
84 success : function(data) {
85 success_fn(data);
genia.likes.science@gmail.com5f425342013-06-13 13:51:26 -070086 },
87 error: function(r) {
88 //alert(JSON.stringify(r));
genia.likes.science@gmail.com1d825142013-06-06 08:01:31 -070089 }
genia.likes.science@gmail.com1d825142013-06-06 08:01:31 -070090 });
91
92 /*$.ajax({
93 "type" : 'GET',
94 "url" : endpoint,
95 "data" : payload,
96 "dataType" : "json",
97 "success" : function(response) {
98
99 alert("DEBUG: Run Response: " + JSON.stringify(response));
100
genia.likes.science@gmail.com5a7c2d72013-06-06 00:54:28 -0700101 if (response && response["error-code"]) {
102
103 alert("Error [Code" + response["error-code"][0] + "]: " + response["error-code"][1]);
104
105 } else if (response && response["results"]) {
106
107 var fn_callback = myThis._callbacks["sync"];
108 fn_callback(response, myThis._extras);
109
110 } else if (response["handle"]) {
111
112 var fn_callback = myThis._callbacks["async"];
113 fn_callback(response, myThis._extras);
114
115 } else if (response["status"]) {
116
117 var fn_callback = myThis._callbacks["sync"];
118 fn_callback(response, myThis._extras);
119 }
genia.likes.science@gmail.com1d825142013-06-06 08:01:31 -0700120 },
121 "error": function (xhr, ajaxOptions, thrownError) {
122 alert("AJAX ERROR " + thrownError);
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700123 }
genia.likes.science@gmail.com1d825142013-06-06 08:01:31 -0700124 });*/
genia.likes.science@gmail.com512454d2013-05-28 03:32:20 -0700125
126 return this;
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700127};
128
129
130AExpression.prototype.val = function() {
131
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700132 var value = "";
133
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700134 // If there is a dataverse defined, provide it.
135 if (this._properties.hasOwnProperty("dataverse")) {
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700136 value += "use dataverse " + this._properties["dataverse"] + ";\n";
137 };
138
139 if (this._properties.hasOwnProperty("value")) {
140 value += this._properties["value"];
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700141 }
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700142
143 return value;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700144};
145
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700146// @param expressionValue [String]
147AExpression.prototype.set = function(expressionValue) {
148 this._properties["value"] = expressionValue;
149 return this;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700150};
151
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700152
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700153// FunctionExpression
154// Parent: AsterixExpression
155//
156// @param options [Various],
157// @key function [String], a function to be applid to the expression
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700158// @key expression [AsterixExpression or AQLClause] an AsterixExpression/Clause to which the fn will be applied
159function FunctionExpression() {
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700160
161 // Initialize superclass
162 AExpression.call(this);
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700163
164 this._properties["function"] = "";
165 this._properties["expression"] = new AExpression().set("");
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700166
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700167 // Check for fn/expression input
168 if (arguments.length == 2 && typeof arguments[0] == "string" &&
169 (arguments[1] instanceof AExpression || arguments[1] instanceof AQLClause)) {
170
171 this._properties["function"] = arguments[0];
172 this._properties["expression"] = arguments[1];
173
174 }
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700175
176 // Return object
177 return this;
178}
179
180
181FunctionExpression.prototype = Object.create(AExpression.prototype);
182FunctionExpression.prototype.constructor = FunctionExpression;
183
184
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700185FunctionExpression.prototype.fn = function(fnName) {
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700186
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700187 if (typeof fnName == "string") {
188 this._properties["function"] = fnName;
189 }
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700190
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700191 return this;
192};
193
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700194
195FunctionExpression.prototype.expression = function(expression) {
196 if (expression instanceof AExpression || expression instanceof AQLClause) {
197 this._properties["expression"] = expression;
198 }
199
200 return this;
201};
202
203
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700204FunctionExpression.prototype.val = function () {
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700205 return this._properties["function"] + "(" + this._properties["expression"].val() + ")";
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700206};
207
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700208
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700209// FLWOGRExpression
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700210//
211// FLWOGRExpression ::= ( ForClause | LetClause ) ( Clause )* "return" Expression
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700212function FLWOGRExpression (options) {
213 // Initialize superclass
214 AExpression.call(this);
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700215
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700216 this._properties["clauses"] = [];
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700217 this._properties["minSize"] = 0;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700218
219 // Bind options and return
220 this.bind(options);
221 return this;
genia.likes.science@gmail.com90d08722013-05-28 04:40:12 -0700222}
223
224
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700225FLWOGRExpression.prototype = Object.create(AExpression.prototype);
226FLWOGRExpression.prototype.constructor = FLWOGRExpression;
227
228
229FLWOGRExpression.prototype.bind = function(options) {
230 AExpression.prototype.bind.call(this, options);
231
232 var options = options || {};
233
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700234 if (options instanceof SetStatement) {
235 this._properties["clauses"].push(options);
236 this._properties["minSize"] += 1;
237 }
238
239 if (this._properties["clauses"].length <= this._properties["minSize"]) {
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700240 // Needs to start with for or let clause
241 if (options instanceof ForClause || options instanceof LetClause) {
242 this._properties["clauses"].push(options);
243 }
244 } else {
245 if (options instanceof AQLClause) {
246 this._properties["clauses"].push(options);
247 }
248 }
249
250 return this;
251};
252
253
254FLWOGRExpression.prototype.val = function() {
255 var value = AExpression.prototype.val.call(this);
256
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700257 var clauseValues = [];
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700258 for (var c in this._properties["clauses"]) {
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700259 clauseValues.push(this._properties["clauses"][c].val());
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700260 }
261
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700262 return value + clauseValues.join("\n");// + ";";
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700263};
264
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700265
genia.likes.science@gmail.com5f425342013-06-13 13:51:26 -0700266FLWOGRExpression.prototype.ReturnClause = function(expression) {
267 return this.bind(new ReturnClause(expression));
268};
269
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700270// AQLClause
271//
272// Base Clause ::= ForClause | LetClause | WhereClause | OrderbyClause | GroupClause | LimitClause | DistinctClause
273function AQLClause() {
274 this._properties = {};
275 this._properties["clause"] = "";
276}
277
278AQLClause.prototype.val = function() {
279 var value = this._properties["clause"];
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700280
281 return value;
282};
283
284AQLClause.prototype.bind = function(options) {
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700285
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700286 if (options instanceof AQLClause) {
287 this._properties["clause"] += " " + options.val();
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700288 }
289
290 return this;
291};
292
genia.likes.science@gmail.com39578302013-05-31 04:42:26 -0700293AQLClause.prototype.set = function(value) {
294 this._properties["clause"] = value;
295 return this;
296};
297
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700298
299// ForClause
300//
301// Grammar:
302// "for" Variable ( "at" Variable )? "in" ( Expression )
303//
304// @param for_variable [String], REQUIRED, first variable in clause
305// @param at_variable [String], NOT REQUIRED, first variable in clause
306// @param expression [AsterixExpression], REQUIRED, expression to evaluate
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700307function ForClause(for_variable, at_variable, expression) {
308 AQLClause.call(this);
309
genia.likes.science@gmail.com78593d72013-07-02 06:33:39 -0700310 this._properties["clause"] = "for " + arguments[0];
genia.likes.science@gmail.comf8cca192013-06-13 15:45:53 -0700311
312 if (arguments.length == 3) {
genia.likes.science@gmail.com78593d72013-07-02 06:33:39 -0700313 this._properties["clause"] += " at " + arguments[1];
genia.likes.science@gmail.comf8cca192013-06-13 15:45:53 -0700314 this._properties["clause"] += " in " + arguments[2].val();
315 } else if (arguments.length == 2) {
316 this._properties["clause"] += " in " + arguments[1].val();
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700317 }
genia.likes.science@gmail.comf8cca192013-06-13 15:45:53 -0700318
genia.likes.science@gmail.com73dcc702013-05-28 04:21:28 -0700319 return this;
320}
321
322ForClause.prototype = Object.create(AQLClause.prototype);
323ForClause.prototype.constructor = ForClause;
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700324
325
326// LetClause
327//
328// Grammar:
329// LetClause ::= "let" Variable ":=" Expression
330//
331// @param let_variable [String]
332// @param expression [AExpression]
333//
334// TODO Vigorous error checking
335function LetClause(let_variable, expression) {
336 AQLClause.call(this);
337
genia.likes.science@gmail.com78593d72013-07-02 06:33:39 -0700338 this._properties["clause"] = "let " + let_variable + " := ";
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700339 this._properties["clause"] += expression.val();
340
341 return this;
342}
343
344LetClause.prototype = Object.create(AQLClause.prototype);
345LetClause.prototype.constructor = LetClause;
346
347
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700348// ReturnClause
349//
350// Grammar:
351// return [AQLExpression]
352function ReturnClause(expression) {
353 AQLClause.call(this);
354
355 this._properties["clause"] = "return ";
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700356
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700357 if (expression instanceof AExpression || expression instanceof AQLClause) {
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700358 this._properties["clause"] += expression.val();
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700359
360 } else if ( typeof expression == "object" && Object.getPrototypeOf( expression ) === Object.prototype ) {
361
362 // TODO Null object check
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700363
364 this._properties["clause"] += "{";
365 var returnStatements = [];
366 for (returnValue in expression) {
367
368 if (expression[returnValue] instanceof AExpression) {
genia.likes.science@gmail.comfba7cc82013-05-31 04:04:08 -0700369 returnStatements.push('"' + returnValue + '" ' + " : " + expression[returnValue].val());
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700370 } else if (typeof expression[returnValue] == "string") {
genia.likes.science@gmail.comfba7cc82013-05-31 04:04:08 -0700371 returnStatements.push('"' + returnValue + '" ' + " : " + expression[returnValue]);
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700372 }
373 }
374 this._properties["clause"] += returnStatements.join(",\n");
genia.likes.science@gmail.comf7929d82013-06-12 11:30:01 -0700375 this._properties["clause"] += "\n}";
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700376
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700377 } else {
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700378 this._properties["clause"] += new AQLClause().set(expression).val();
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700379 }
380
381 return this;
382}
383
genia.likes.science@gmail.com5749ef92013-06-12 07:59:25 -0700384
genia.likes.science@gmail.com5ca104c2013-05-29 05:39:26 -0700385ReturnClause.prototype = Object.create(AQLClause.prototype);
386ReturnClause.prototype.constructor = ReturnClause;
387
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700388
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700389// WhereClause
390//
391// Grammar:
392// ::= "where" Expression
393//
394// @param expression [BooleanExpression], pushes this expression onto the stack
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700395function WhereClause(expression) {
396 AQLClause.call(this);
397
398 this._properties["stack"] = [];
399
400 this.bind(expression);
401
402 return this;
403}
404
405
406WhereClause.prototype = Object.create(AQLClause.prototype);
407WhereClause.prototype.constructor = WhereClause;
408
409
410WhereClause.prototype.bind = function(expression) {
genia.likes.science@gmail.com64ca88e2013-05-31 10:40:39 -0700411 if (expression instanceof AExpression) {
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700412 this._properties["stack"].push(expression);
413 }
414};
415
416
417WhereClause.prototype.val = function() {
418 var value = "where ";
419
420 var count = this._properties["stack"].length - 1;
421 while (count >= 0) {
422 value += this._properties["stack"][count].val() + " ";
423 count -= 1;
424 }
425
426 return value;
genia.likes.science@gmail.com64ca88e2013-05-31 10:40:39 -0700427};
genia.likes.science@gmail.com38612632013-05-28 13:11:52 -0700428
429
genia.likes.science@gmail.comd2f753e2013-06-12 13:51:03 -0700430WhereClause.prototype.and = function() {
431
432 var andClauses = [];
433 for (var expression in arguments) {
434
435 if (arguments[expression] instanceof AExpression) {
436 andClauses.push(arguments[expression].val());
437 }
438 }
439
440 if (andClauses.length > 0) {
441 this._properties["stack"].push(new AExpression().set(andClauses.join(" and ")));
442 }
443
444 return this;
445};
446
447
448WhereClause.prototype.or = function() {
449 var orClauses = [];
450 for (var expression in arguments) {
451
452 if (arguments[expression] instanceof AExpression) {
453 orClauses.push(arguments[expression].val());
454 }
455 }
456
457 if (andClauses.length > 0) {
458 this._properties["stack"].push(new AExpression().set(orClauses.join(" and ")));
459 }
460
461 return this;
462};
463
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700464// LimitClause
465// Grammar:
466// LimitClause ::= "limit" Expression ( "offset" Expression )?
467//
468// @param limitExpression [REQUIRED, AQLExpression]
469// @param offsetExpression [OPTIONAL, AQLExpression]
470function LimitClause(limitExpression, offsetExpression) {
471
472 AQLClause.call(this);
473
474 // limitExpression required
475 this._properties["clause"] = "limit " + limitExpression.val();
476
477 // Optional: Offset
478 var offset = typeof offsetExpression ? offsetExpression : null;
479 if (offset != null) {
480 this._properties["clause"] += " offset " + offsetExpression.val();
481 }
482
483 return this;
484}
485
486LimitClause.prototype = Object.create(AQLClause.prototype);
487LimitClause.prototype.constructor = LimitClause;
488
489
490// OrderbyClause
491//
492// Grammar:
493// OrderbyClause ::= "order" "by" Expression ( ( "asc" ) | ( "desc" ) )? ( "," Expression ( ( "asc" ) | ( "desc" ) )? )*
494//
495// @params AQLExpressions and asc/desc strings, in any quantity. At least one required.
496function OrderbyClause() {
497
498 AQLClause.call(this);
499
500 // At least one argument expression is required, and first should be expression
501 if (arguments.length == 0 || !(arguments[0] instanceof AExpression)) {
genia.likes.science@gmail.com18f3bf22013-06-12 07:45:02 -0700502
genia.likes.science@gmail.com2ba32242013-05-31 03:10:48 -0700503 // TODO Not sure which error to throw for an empty OrderBy but this should fail.
504 alert("Order By Error");
505 this._properties["clause"] = null;
506 return this;
507 }
508
509 var expc = 0;
510 var expressions = [];
511
512 while (expc < arguments.length) {
513
514 var expression = "";
515
516 if (arguments[expc] instanceof AExpression) {
517 expression += arguments[expc].val();
518 }
519
520 var next = expc + 1;
521 if (next < arguments.length && (arguments[next] == "asc" || arguments[next] == "desc")) {
522 expc++;
523 expression += " " + arguments[expc];
524 }
525
526 expressions.push(expression);
527
528 expc++;
529 }
530
531 this._properties["clause"] = "order by " + expressions.join(", ");
532 return this;
533}
534
535OrderbyClause.prototype = Object.create(AQLClause.prototype);
536OrderbyClause.prototype.constructor = OrderbyClause;
537
538
genia.likes.science@gmail.com6e392912013-05-31 03:46:59 -0700539// GroupClause
540//
541// Grammar:
542// GroupClause ::= "group" "by" ( Variable ":=" )? Expression ( "," ( Variable ":=" )? Expression )* ( "decor" Variable ":=" Expression ( "," "decor" Variable ":=" Expression )* )? "with" VariableRef ( "," VariableRef )*
543function GroupClause() {
544 AQLClause.call(this);
545
546 if (arguments.length == 0) {
547 // TODO Not sure which error to throw for an empty GroupBy but this should fail.
548 alert("Group Error");
549 this._properties["clause"] = null;
550 return this;
551 }
552
553 var expc = 0;
554 var expressions = [];
555 var variableRefs = [];
556 var isDecor = false;
genia.likes.science@gmail.com5f425342013-06-13 13:51:26 -0700557
genia.likes.science@gmail.com6e392912013-05-31 03:46:59 -0700558 while (expc < arguments.length) {
559
560 if (arguments[expc] instanceof AExpression) {
561
562 isDecor = false;
563 expressions.push(arguments[expc].val());
564
565 } else if (typeof arguments[expc] == "string") {
566
567 // Special keywords, decor & with
568 if (arguments[expc] == "decor") {
569 isDecor = true;
570 } else if (arguments[expc] == "with") {
571 isDecor = false;
572 expc++;
573 while (expc < arguments.length) {
574 variableRefs.push("$" + arguments[expc]);
575 expc++;
576 }
577
578 // Variables and variable refs
579 } else {
580
581 var nextc = expc + 1;
582 var expression = "";
583
584 if (isDecor) {
585 expression += "decor ";
586 isDecor = false;
587 }
588
589 expression += "$" + arguments[expc] + " := " + arguments[nextc].val();
590 expressions.push(expression);
591 expc++;
592 }
593 }
594
595 expc++;
596 }
597
598 this._properties["clause"] = "group by " + expressions.join(", ") + " with " + variableRefs.join(", ");
599 return this;
600}
601
602GroupClause.prototype = Object.create(AQLClause.prototype);
603GroupClause.prototype.constructor = GroupClause;
604
genia.likes.science@gmail.com79e603a2013-05-31 10:03:23 -0700605
606// SetStatement
607//
608// Grammar
609// "set" Identifier StringLiteral
610function SetStatement (identifier, stringLiteral) {
611 AExpression.call(this);
612
613 var statement = "set " + identifier + ' "' + stringLiteral + '";';
614
615 AExpression.prototype.set.call(this, statement);
616
617 return this;
618}
619
620SetStatement.prototype = Object.create(AExpression.prototype);
621SetStatement.prototype.constructor = SetStatement;
genia.likes.science@gmail.come34c57b2013-05-31 10:15:49 -0700622
623
624// Quantified Expression
625//
626// Grammar
627// QuantifiedExpression ::= ( ( "some" ) | ( "every" ) ) Variable "in" Expression ( "," Variable "in" Expression )* "satisfies" Expression
628//
629// @param String some/every
630// @param [AExpression]
631// @param [Aexpression] satisfiesExpression
632function QuantifiedExpression (keyword, expressions, satisfiesExpression) {
633 AExpression.call(this);
634
635 var expression = keyword + " ";
636 var varsInExpressions = [];
637
638 for (var varInExpression in expressions) {
639 varsInExpressions.push(varInExpression + " in " + expressions[varInExpression].val());
640 }
641 expression += varsInExpressions.join(", ") + " satisfies " + satisfiesExpression.val();
642
643 AExpression.prototype.set.call(this, expression);
644
645 return this;
646}
647
648QuantifiedExpression.prototype = Object.create(AExpression.prototype);
649QuantifiedExpression.prototype.constructor = QuantifiedExpression;
genia.likes.science@gmail.com64ca88e2013-05-31 10:40:39 -0700650
651QuantifiedExpression.prototype.val = function() {
652 var value = AExpression.prototype.val.call(this);
653 return "(" + value + ")";
654};