Comparing version 0.3.0 to 0.4.0
@@ -14,3 +14,3 @@ /** | ||
Object.defineProperty(loader, 'version', { | ||
value: '0.3.0' | ||
value: '0.4.0' | ||
}); | ||
@@ -17,0 +17,0 @@ |
{ | ||
"name": "decypher", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A handful of cypher utilities for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -109,2 +109,4 @@ [![Build Status](https://travis-ci.org/Yomguithereal/decypher.svg)](https://travis-ci.org/Yomguithereal/decypher) | ||
The result object of the builder is also made to match **@thingdom**'s [node-neo4j](https://github.com/thingdom/node-neo4j/tree/v2#readme) specifications for the `db.cypher` method. | ||
```js | ||
@@ -123,5 +125,5 @@ var Query = require('decypher').Query; | ||
cypher.toString(); | ||
// MATCH (n:Node) | ||
// WHERE n.title = {title} | ||
// RETURN n; | ||
>>> `MATCH (n:Node) | ||
WHERE n.title = {title} | ||
RETURN n;` | ||
@@ -145,4 +147,3 @@ // Retrieving the query's parameters | ||
// Note that multi words statements like `ORDER BY` | ||
// have to be written in camel-case: | ||
// Note that multi words statements like `ORDER BY` have to be written in camel-case: | ||
cypher.orderBy('n.title'); | ||
@@ -158,5 +159,17 @@ | ||
// Finally, you can add arbitrary parts to the query if required | ||
// You can also add arbitrary parts to the query if required | ||
cypher.add('anything you want'); | ||
cypher.add('with {param}', {param: 'heart'}); | ||
// Finally, you can segment your query for convenience | ||
var cypher = new Query(), | ||
start = cypher.segment(), | ||
end = cypher.segment(); | ||
end.return('a'); | ||
start.match('(a:Actor)'); | ||
cypher.compile(); | ||
>>> `MATCH (a:Actor) | ||
RETURN a;` | ||
``` | ||
@@ -163,0 +176,0 @@ |
@@ -25,9 +25,19 @@ /** | ||
// Properties | ||
this._statements = []; | ||
this._segments = []; | ||
this._params = {}; | ||
} | ||
// Appending a segment to the query | ||
Query.prototype.segment = function() { | ||
var query = new Query(); | ||
this._segments.push(query); | ||
return query; | ||
}; | ||
// Retrieving statements | ||
Query.prototype.statements = function() { | ||
return this._statements.slice(0); | ||
return this._segments.reduce(function(acc, segment) { | ||
return acc.concat(segment instanceof Query ? segment.statements() : segment); | ||
}, []); | ||
}; | ||
@@ -37,3 +47,3 @@ | ||
Query.prototype.compile = function() { | ||
return this._statements.join('\n') + ';'; | ||
return this.statements().join('\n') + ';'; | ||
}; | ||
@@ -44,5 +54,14 @@ Query.prototype.toString = Query.prototype.compile; | ||
Query.prototype.params = function(params) { | ||
if (!params) | ||
return this._params; | ||
if (!params) { | ||
var additionalParams = this._segments | ||
.filter(function(segment) { | ||
return segment instanceof Query; | ||
}) | ||
.map(function(segment) { | ||
return segment.params(); | ||
}); | ||
return assign.apply(null, additionalParams.concat(this._params)); | ||
} | ||
if (!isPlainObject(params)) | ||
@@ -94,5 +113,6 @@ throw Error('decypher.Query.params: passed parameters should be a plain object.'); | ||
this._statements.push(string); | ||
this._segments.push(string); | ||
assign(this._params, params); | ||
if (params) | ||
this.params(params); | ||
@@ -99,0 +119,0 @@ return this; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
23852
575
313
0