Skip to content

Commit de9ac28

Browse files
Adding arithmetic variable treatment (terminusdb#296)
1 parent 060a3dc commit de9ac28

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

lib/query/woqlQuery.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ WOQLQuery.prototype.plus = function (...args) {
934934
this.cursor['@type'] = 'Plus';
935935
this.cursor.left = this.arop(args.shift());
936936
if (args.length > 1) {
937-
this.cursor.right = this.jobj(new WOQLQuery().plus(...args));
937+
this.cursor.right = this.jobj(new WOQLQuery().plus(...args.map(this.arop)));
938938
} else {
939939
this.cursor.right = this.arop(args[0]);
940940
}
@@ -954,7 +954,7 @@ WOQLQuery.prototype.minus = function (...args) {
954954
this.cursor['@type'] = 'Minus';
955955
this.cursor.left = this.arop(args.shift());
956956
if (args.length > 1) {
957-
this.cursor.right = this.jobj(new WOQLQuery().minus(...args));
957+
this.cursor.right = this.jobj(new WOQLQuery().minus(...args.map(this.arop)));
958958
} else {
959959
this.cursor.right = this.arop(args[0]);
960960
}
@@ -973,7 +973,7 @@ WOQLQuery.prototype.times = function (...args) {
973973
this.cursor['@type'] = 'Times';
974974
this.cursor.left = this.arop(args.shift());
975975
if (args.length > 1) {
976-
this.cursor.right = this.jobj(new WOQLQuery().times(...args));
976+
this.cursor.right = this.jobj(new WOQLQuery().times(...args.map(this.arop)));
977977
} else {
978978
this.cursor.right = this.arop(args[0]);
979979
}
@@ -991,7 +991,7 @@ WOQLQuery.prototype.divide = function (...args) {
991991
this.cursor['@type'] = 'Divide';
992992
this.cursor.left = this.arop(args.shift());
993993
if (args.length > 1) {
994-
this.cursor.right = this.jobj(new WOQLQuery().divide(...args));
994+
this.cursor.right = this.jobj(new WOQLQuery().divide(...args.map(this.arop)));
995995
} else {
996996
this.cursor.right = this.arop(args[0]);
997997
}
@@ -1010,7 +1010,7 @@ WOQLQuery.prototype.div = function (...args) {
10101010
this.cursor['@type'] = 'Div';
10111011
this.cursor.left = this.arop(args.shift());
10121012
if (args.length > 1) {
1013-
this.cursor.right = this.jobj(new WOQLQuery().div(...args));
1013+
this.cursor.right = this.jobj(new WOQLQuery().div(...args.map(this.arop)));
10141014
} else {
10151015
this.cursor.right = this.arop(args[0]);
10161016
}

lib/woql.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,18 @@ WOQL.evaluate = function (arithExp, resultVarName) {
502502
};
503503

504504
/**
505+
*
505506
* Evaluates the passed arithmetic expression and generates or matches the result value
506-
* @param {object| WOQLQuery | string} arithExp - query or JSON-LD representing the query
507-
* @param {string|Var} resultVarName - output variable
508-
* @returns {WOQLQuery} WOQLQuery
507+
* @param {object| WOQLQuery | string} arithExp - A WOQL query containing a valid WOQL Arithmetic
508+
* Expression, which is evaluated by the function
509+
* @param {string|number|Var} resultVarName - Either a variable, in which the result of the
510+
* expression will be stored, or a numeric literal which will be used as a test of result of
511+
* the evaluated expression
512+
* @returns {WOQLQuery} A WOQLQuery which contains the Arithmetic function
513+
* @example
514+
* let [result] = vars("result")
515+
* eval(plus(2, minus(3, 1)), result)
509516
*/
510-
511517
WOQL.eval = function (arithExp, resultVarName) {
512518
return new WOQLQuery().eval(arithExp, resultVarName);
513519
};

0 commit comments

Comments
 (0)