Commit aae4a9af authored by Tristan Cavelier's avatar Tristan Cavelier

Query create(create(...)) bug fixed

parent e2fee8eb
...@@ -24,7 +24,7 @@ function ComplexQuery(spec, key_schema) { ...@@ -24,7 +24,7 @@ function ComplexQuery(spec, key_schema) {
* @default "AND" * @default "AND"
* @optional * @optional
*/ */
this.operator = spec.operator || "AND"; this.operator = spec.operator;
/** /**
* The sub Query list which are used to query an item. * The sub Query list which are used to query an item.
...@@ -45,6 +45,9 @@ function ComplexQuery(spec, key_schema) { ...@@ -45,6 +45,9 @@ function ComplexQuery(spec, key_schema) {
} }
inherits(ComplexQuery, Query); inherits(ComplexQuery, Query);
ComplexQuery.prototype.operator = "AND";
ComplexQuery.prototype.type = "complex";
/** /**
* #crossLink "Query/match:method" * #crossLink "Query/match:method"
*/ */
...@@ -60,12 +63,20 @@ ComplexQuery.prototype.match = function (item) { ...@@ -60,12 +63,20 @@ ComplexQuery.prototype.match = function (item) {
* #crossLink "Query/toString:method" * #crossLink "Query/toString:method"
*/ */
ComplexQuery.prototype.toString = function () { ComplexQuery.prototype.toString = function () {
var str_list = ["("], this_operator = this.operator; var str_list = [], this_operator = this.operator;
if (this.operator === "NOT") {
str_list.push("NOT (");
str_list.push(this.query_list[0].toString());
str_list.push(")");
return str_list.join(" ");
}
this.query_list.forEach(function (query) { this.query_list.forEach(function (query) {
str_list.push("(");
str_list.push(query.toString()); str_list.push(query.toString());
str_list.push(")");
str_list.push(this_operator); str_list.push(this_operator);
}); });
str_list[str_list.length - 1] = ")"; // replace last operator str_list.length -= 1;
return str_list.join(" "); return str_list.join(" ");
}; };
...@@ -79,7 +90,9 @@ ComplexQuery.prototype.serialized = function () { ...@@ -79,7 +90,9 @@ ComplexQuery.prototype.serialized = function () {
"query_list": [] "query_list": []
}; };
this.query_list.forEach(function (query) { this.query_list.forEach(function (query) {
s.query_list.push(query.serialized()); s.query_list.push(
typeof query.toJSON === "function" ? query.toJSON() : query
);
}); });
return s; return s;
}; };
......
...@@ -77,6 +77,7 @@ function SimpleQuery(spec, key_schema) { ...@@ -77,6 +77,7 @@ function SimpleQuery(spec, key_schema) {
} }
inherits(SimpleQuery, Query); inherits(SimpleQuery, Query);
SimpleQuery.prototype.type = "simple";
var checkKey = function (key) { var checkKey = function (key) {
var prop; var prop;
......
...@@ -226,6 +226,29 @@ ...@@ -226,6 +226,29 @@
jsoned, jsoned,
"parseStringToObject(\"NOT(a:=b OR c:% AND d:<2)\");" "parseStringToObject(\"NOT(a:=b OR c:% AND d:<2)\");"
); );
deepEqual(
jIO.QueryFactory.create(
"NOT(a:=b OR c:% AND d:<2)"
),
jIO.QueryFactory.create(
jIO.QueryFactory.create(
"NOT(a:=b OR c:% AND d:<2)"
)
),
"create(create(\"NOT(a:=b OR c:% AND d:<2)\"));"
);
deepEqual(
jIO.QueryFactory.create(
jIO.QueryFactory.create(
"NOT(a:=b OR c:% AND d:<2)"
)
).toString(),
"NOT ( ( a: = \"b\" ) OR ( ( c: \"%\" ) AND ( d: < \"2\" ) ) )",
"create(create(\"NOT(a:=b OR c:% AND d:<2)\")).toString();"
);
}); });
})); }));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment