Skip to content

Commit 50864a7

Browse files
Adding some fixes for WOQL
1 parent c1ca0e4 commit 50864a7

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

lib/woql.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ WOQL.unique = function(prefix, vari, type){ return new WOQLQuery().unique(prefix
5151
WOQL.idgen = function(prefix, vari, type, output){ return new WOQLQuery().idgen(prefix, vari, type, output); }
5252
WOQL.typecast = function(vara, type, varb){ return new WOQLQuery().typecast(vara, type, varb); }
5353

54+
WOQL.less = function(v1, v2){ return new WOQLQuery().less(v1, v2); }
55+
WOQL.greater = function(v1, v2){ return new WOQLQuery().greater(v1, v2); }
56+
5457

5558
/* Mathematical Processing */
5659
WOQL.eval = function(arith, v){ return new WOQLQuery().eval(arith, v);}
@@ -286,6 +289,16 @@ WOQLQuery.prototype.join = function(...list){
286289
return this;
287290
}
288291

292+
WOQLQuery.prototype.less = function(v1, v2){
293+
this.cursor['less'] = [v1, v2];
294+
return this;
295+
}
296+
297+
WOQLQuery.prototype.greater = function(v1, v2){
298+
this.cursor['greater'] = [v1, v2];
299+
return this;
300+
}
301+
289302

290303
WOQLQuery.prototype.list = function(...vars){
291304
this.cursor['list'] = vars;
@@ -440,14 +453,20 @@ WOQLQuery.prototype.sub = function(a, b){
440453
}
441454

442455
WOQLQuery.prototype.comment = function(val){
443-
if(val){
444-
val = (val.json ? val.json() : val)
445-
this.cursor['comment'] = val;
456+
if(val && val.json){
457+
this.cursor['comment'] = [val.json()];
458+
}
459+
else if(typeof val == "string"){
460+
this.cursor['comment'] = [val];
461+
}
462+
else if(typeof val == "object"){
463+
if(val.length) this.cursor['comment'] = val;
464+
else this.cursor['comment'] = [val];
446465
}
447466
else {
448-
this.cursor['comment'] = null;
449-
this.cursor = this.cursor['comment'];
467+
this.cursor['comment'] = [];
450468
}
469+
this.cursor = this.cursor['comment'][this.cursor['comment'].length];
451470
return this;
452471
}
453472

@@ -684,7 +703,7 @@ WOQLQuery.prototype.label = function(l, lang){
684703
}
685704

686705
WOQLQuery.prototype.description = function(c, lang){
687-
if(this.tripleBuilder) this.tripleBuilder.comment(c, lang);
706+
if(this.tripleBuilder) this.tripleBuilder.description(c, lang);
688707
return this;
689708
}
690709

@@ -1219,7 +1238,7 @@ WOQLQuery.prototype.getWOQLPrelude = function(operator, fluent, inline){
12191238
*/
12201239
WOQLQuery.prototype.chainable = function(operator, lastArg){
12211240
const non_chaining_operators = ["and", "or"];
1222-
if(typeof lastArg == "object" && typeof lastArg['@value'] == "undefined" && typeof lastArg['@type'] == "undefined" && typeof lastArg['value'] == "undefined" && non_chaining_operators.indexOf(operator) == -1){
1241+
if(lastArg && typeof lastArg == "object" && typeof lastArg['@value'] == "undefined" && typeof lastArg['@type'] == "undefined" && typeof lastArg['value'] == "undefined" && non_chaining_operators.indexOf(operator) == -1){
12231242
return true;
12241243
}
12251244
return false;
@@ -1348,9 +1367,13 @@ WOQLQuery.prototype.uncleanObjectArgument = function(operator, val, index){
13481367
return JSON.stringify(val);
13491368
}
13501369

1351-
WOQLQuery.prototype.argIsSubQuery = function(operator, args){
1352-
const squery_operators = ["and", "or", "when", "not", "opt"];
1353-
return (squery_operators.indexOf(operator) !== -1);
1370+
WOQLQuery.prototype.argIsSubQuery = function(operator, arg, index){
1371+
const squery_operators = ["and", "or", "when", "not", "opt", "exp", "minus", "div", "divide", "plus", "multiply"];
1372+
if(squery_operators.indexOf(operator) !== -1){
1373+
if(arg && typeof arg != "object") return false;
1374+
return true;
1375+
}
1376+
else return false;
13541377
}
13551378

13561379
/**
@@ -1463,7 +1486,7 @@ TripleBuilder.prototype.label = function(l, lang){
14631486
return x;
14641487
}
14651488

1466-
TripleBuilder.prototype.comment = function(c, lang){
1489+
TripleBuilder.prototype.description = function(c, lang){
14671490
lang = (lang ? lang : "en");
14681491
if(c.substring(0, 2) == "v:"){
14691492
var d = {"value": l, "@language": lang }

0 commit comments

Comments
 (0)