Comparing version 0.6.1 to 0.7.0
{ | ||
"name": "decypher", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "A handful of cypher utilities for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -203,2 +203,5 @@ [](https://travis-ci.org/Yomguithereal/decypher) | ||
>>> 'a = b OR (c = d AND e = f)' | ||
expr.isEmpty(); | ||
>>> false | ||
``` | ||
@@ -205,0 +208,0 @@ |
@@ -20,3 +20,3 @@ /** | ||
if (firstString) | ||
this._parts.push({operator: 'and', value: firstString}); | ||
this.and(firstString); | ||
} | ||
@@ -32,5 +32,11 @@ | ||
// Checking whether the expression is empty | ||
Expression.prototype.isEmpty = function() { | ||
return !this.compile(); | ||
}; | ||
// Compiling the expression to string | ||
Expression.prototype.compile = function() { | ||
var string = '', | ||
value, | ||
part, | ||
@@ -43,9 +49,13 @@ i, | ||
if (i) | ||
if (string) | ||
string += ' ' + part.operator.toUpperCase() + ' '; | ||
if (part.value instanceof Expression) | ||
string += '(' + part.value.compile() + ')'; | ||
else | ||
if (part.value instanceof Expression) { | ||
value = part.value.compile(); | ||
if (!!value) | ||
string += '(' + value + ')'; | ||
} | ||
else { | ||
string += part.value; | ||
} | ||
} | ||
@@ -52,0 +62,0 @@ |
@@ -120,7 +120,9 @@ /** | ||
var valid = parts.every(function(part) { | ||
return typeof part === 'string' || part instanceof Expression; | ||
return !!part && | ||
typeof part === 'string' || | ||
(part instanceof Expression && !part.isEmpty()); | ||
}); | ||
if (!valid) | ||
throw Error('decypher.Query.' + methodName + ': first parameter should be a string.'); | ||
throw Error('decypher.Query.' + methodName + ': first parameter should not be falsy or empty.'); | ||
@@ -127,0 +129,0 @@ var string = ''; |
29351
696
388