cypher-stream
Advanced tools
Comparing version 1.0.0-alpha to 1.0.0-alpha.1
@@ -20,5 +20,2 @@ 'use strict'; | ||
// Recursively map Neo4j values | ||
// to their native equivalants | ||
// session => statement => observable | ||
@@ -52,6 +49,7 @@ var run = curry((runner, statement) => | ||
constructor(runner, statements) { | ||
constructor(runner, statements, options) { | ||
super({ objectMode: true }); | ||
this.statements = statements; | ||
this.runner = runner; | ||
this.runner = runner; | ||
this.options = options || {}; | ||
this.start(); | ||
@@ -65,9 +63,15 @@ } | ||
.flatMap(statement => { | ||
var stream = | ||
runStream(this.runner, statement) | ||
.map(toNative); | ||
var stream = runStream(this.runner, statement); | ||
if('neo4j' !== this.options.returnType) { | ||
stream = stream.map(toNative); | ||
} | ||
if(statement.callback) { | ||
statement.callback(stream.observe()); | ||
} | ||
return stream; | ||
}) | ||
@@ -74,0 +78,0 @@ .errors(handleError(emitError(this))) |
@@ -15,3 +15,3 @@ 'use strict'; | ||
var notNil = compose(not, isNil); | ||
var notNil = compose(not, isNil); | ||
@@ -29,3 +29,3 @@ // (user, pass) => auth || undefined | ||
var factory = function CypherStreamFactory(statement, parameters) { | ||
var factory = function CypherStreamFactory(statement, parameters, options) { | ||
if (parameters) { | ||
@@ -35,3 +35,3 @@ statement = [ { statement, parameters } ]; | ||
var session = driver.session(); | ||
return new CypherStream(session, statement) | ||
return new CypherStream(session, statement, options) | ||
.on('end', () => session.close()); | ||
@@ -46,3 +46,6 @@ }; | ||
factory.driver = driver; | ||
factory.neo4j = neo4j; | ||
return factory; | ||
}; |
{ | ||
"name": "cypher-stream", | ||
"version": "1.0.0-alpha", | ||
"version": "1.0.0-alpha.1", | ||
"description": "Streams cypher query results in a clean format", | ||
@@ -27,12 +27,11 @@ "main": "index.js", | ||
"neo4j-driver": "^1.0.3", | ||
"oboe": "^2.1.1", | ||
"ramda": "^0.21.0" | ||
"ramda": "^0.22.1" | ||
}, | ||
"devDependencies": { | ||
"coveralls": "^2.11.2", | ||
"mocha-lcov-reporter": "0.0.1", | ||
"mocha": "~1.17.1", | ||
"should": "~3.1.3", | ||
"istanbul": "^0.3.2" | ||
"mocha-lcov-reporter": "1.2.0", | ||
"mocha": "~3.0.2", | ||
"should": "~11.1.0", | ||
"istanbul": "^0.4.4" | ||
} | ||
} |
# cypher-stream | ||
[](https://gitter.im/brian-gates/cypher-stream?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
[](https://travis-ci.org/brian-gates/cypher-stream) [](http://badge.fury.io/js/cypher-stream) [](https://david-dm.org/brian-gates/cypher-stream.png#info=devDependencies) [](https://coveralls.io/r/brian-gates/cypher-stream) | ||
[](https://gitter.im/codex-digital/cypher-stream?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
[](https://travis-ci.org/codex-digital/cypher-stream) [](http://badge.fury.io/js/cypher-stream) [](https://david-dm.org/codex-digital/cypher-stream.png#info=devDependencies) [](https://coveralls.io/r/codex-digital/cypher-stream) | ||
Neo4j cypher queries as node object streams. | ||
## 1.0.0-alpha | ||
1.0.0-alpha is Powered by Bolt™. Updated documentation is forthcoming. For the brave, check the source, tests, and go wild. | ||
The API is largely unchanged, with the exception of authentication and some configuration options which no longer make sense in the Bolt world (i.e. http headers). | ||
Performance should be significantly improved, given that the library no longer has to stream-parse HTTP JSON responses. | ||
TODO: | ||
* Documentation / Migration guide | ||
* Facilitate access to underlying Neo4j objects | ||
* Benchmark | ||
## Installation | ||
@@ -12,6 +26,12 @@ ``` | ||
Or, for Bolt | ||
``` | ||
npm install cypher-stream@1.0.0-alpha | ||
``` | ||
## Basic usage | ||
``` js | ||
var cypher = require('cypher-stream')('http://localhost:7474'); | ||
var cypher = require('cypher-stream')('bolt://localhost', 'username', 'password'); | ||
@@ -30,3 +50,3 @@ cypher('match (user:User) return user') | ||
``` js | ||
var cypher = require('cypher-stream')('http://localhost:7474'); | ||
var cypher = require('cypher-stream')('bolt://localhost', 'username', 'password'); | ||
var should = require('should'); | ||
@@ -95,3 +115,2 @@ it('handles errors', function (done) { | ||
``` js | ||
@@ -114,20 +133,2 @@ transaction.commit(); | ||
### Query Batching | ||
Transactions automatically batch queries for significant performance gains. Try the following: | ||
``` js | ||
var queriesToRun = 10000; | ||
var queriesWritten = 0; | ||
var transaction = cypher.transaction() | ||
.on('data', function (result) { | ||
console.log(result); | ||
}) | ||
; | ||
while (queriesWritten++ < queriesToRun) { | ||
transaction.write('match (n:Test) return n limit 1'); | ||
} | ||
transaction.commit(); | ||
``` | ||
## Stream per statement | ||
@@ -134,0 +135,0 @@ |
'use strict'; | ||
var cypher = require('../index')('bolt://0.0.0.0'); | ||
var neo4j = require('neo4j-driver').v1; | ||
var R = require('ramda'); | ||
var should = require('should'); | ||
var R = require('ramda'); | ||
@@ -28,2 +29,6 @@ var shouldNotError = error => should.not.exist(error); | ||
it('exposes base Neo4j Node and Relationship for external comparisons', () => { | ||
cypher.neo4j.types.should.have.properties('Node', 'Relationship'); | ||
}); | ||
it('works', done => { | ||
@@ -184,2 +189,17 @@ var results = 0; | ||
it('can return Neo4j data types', done => { | ||
cypher(`match (n:Test) return n limit 1`, {}, { returnType: 'neo4j' }) | ||
.on('data', data => { | ||
data.should.have.properties([ | ||
'_fields', | ||
'keys', | ||
'length', | ||
'_fieldLookup', | ||
]); | ||
}) | ||
.on('end', done) | ||
; | ||
}); | ||
}); |
@@ -333,2 +333,20 @@ 'use strict'; | ||
it('can return Neo4j data types', done => { | ||
var tx = cypher.transaction({ returnType: 'neo4j' }); | ||
tx.on('data', data => { | ||
data.should.have.properties([ | ||
'_fields', | ||
'keys', | ||
'length', | ||
'_fieldLookup', | ||
]); | ||
}); | ||
tx.write('MATCH (n:Test) return n LIMIT 1'); | ||
tx.commit(); | ||
tx.resume(); | ||
tx.on('end', done); | ||
}); | ||
}); |
@@ -12,3 +12,3 @@ 'use strict'; | ||
class TransactionStream extends Duplex { | ||
constructor(session) { | ||
constructor(session, options) { | ||
super({ objectMode: true }); | ||
@@ -26,3 +26,3 @@ | ||
} | ||
return $(new CypherStream(this.tx, statement)); | ||
return $(new CypherStream(this.tx, statement, options)); | ||
}) | ||
@@ -29,0 +29,0 @@ ; |
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
3
190
0
43526
18
776
+ Addedramda@0.22.1(transitive)
- Removedoboe@^2.1.1
- Removedhttp-https@1.0.0(transitive)
- Removedoboe@2.1.7(transitive)
- Removedramda@0.21.0(transitive)
Updatedramda@^0.22.1