Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cypher-stream

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cypher-stream - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

.travis.yml

55

index.js

@@ -1,16 +0,45 @@

var request = require('request');
var Neo4jStreamDeserializer = require('neo4j-stream-deserializer');
var oboe = require('oboe');
var Readable = require('stream').Readable;
var util = require('util');
module.exports = function(url) {
return function(query, params) {
var form = { query: query };
if(params) {
form.params = params;
}
return request.post({
url : url,
form : form,
headers : { "X-Stream": true, "Accept": "application/json" }
}).pipe(new Neo4jStreamDeserializer());
util.inherits(CypherStream, Readable);
function CypherStream (url, query, params) {
Readable.call(this, { objectMode: true });
var columns;
var stream = this;
oboe({
url : url+'/db/data/cypher',
method : 'POST',
headers : { "X-Stream": true, "Accept": "application/json" },
body : { query: query, params: params }
})
.node('!columns', function (c) {
stream.emit('columns', c);
columns = c;
this.forget();
})
.node('!data[*]', function (result, path, ancestors) {
var data = {};
columns.forEach(function (column, i) {
data[column] = result[i].data
});
stream.push(data)
})
.done(function (complete) {
stream.push(null);
})
.fail(function(error) {
stream.emit('error', error);
stream.push(null);
});
this._read = function () { }
return this;
};
module.exports = function Connection(url) {
return function CypherStreamFactory (query, params) {
return new CypherStream(url, query, params);
}
};
{
"name": "cypher-stream",
"version": "0.0.1",
"version": "0.1.0",
"description": "Streams cypher query results in a clean format",

@@ -25,4 +25,3 @@ "main": "index.js",

"dependencies": {
"neo4j-stream-deserializer": "git://github.com/brian-gates/neo4j-stream-deserializer.git",
"request": "~2.33.0"
"oboe": "~1.12.2"
},

@@ -29,0 +28,0 @@ "devDependencies": {

@@ -1,10 +0,18 @@

# cypher-stream
# cypher-stream [![NPM version](https://badge.fury.io/js/cypher-stream.png)](http://badge.fury.io/js/cypher-stream) [![devDependency Status](https://david-dm.org/brian-gates/cypher-stream.png?theme=shields.io)](https://david-dm.org/brian-gates/cypher-stream.png#info=devDependencies)
Streams cypher query results as easy to manage objects.
Neo4j cypher queries as node object streams.
The majority of magic happens in the deserializer, which can be found here:
https://github.com/brian-gates/neo4j-stream-deserializer
## Installation
```
npm install cypher-stream
```
## Basic usage
``` js
var neo4j_cypher_stream = require('cypher-stream');
var cypher = neo4j_cypher_stream('http://localhost:7474/db/data/cypher');
var cypher = require('cypher-stream')('http://localhost:7474');

@@ -20,1 +28,19 @@ cypher('match (user:User) return user')

```
## Handling errors
``` js
var cypher = require('cypher-stream')('http://localhost:7474');
cypher('invalid query')
.on('data', function (data){
console.log(data); // never called
})
.on('error', function (error) {
console.log(error.statusCode); // 400
})
.on('end', function() {
console.log('all done');
})
;
});
```

@@ -1,10 +0,19 @@

var neo4j_cypher_stream = require('../index');
var should = require('should');
var cypher = neo4j_cypher_stream('http://localhost:7474/db/data/cypher');
var cypher = require('../index')('http://localhost:7474');
describe('Cypher stream', function () {
before(function (done){
cypher('FOREACH (x IN range(1,10) | CREATE(:Test {test: true}))')
.on('end', done)
.resume();
});
after(function (done){
cypher('MATCH (n:Test) DELETE n')
.on('end', done)
.resume();
});
it('it works', function (done) {
it('works', function (done) {
var results = 0;
cypher('match (n {test: true}) return n limit 10')
cypher('match (n:Test) return n limit 10')
.on('data', function (result){

@@ -21,2 +30,19 @@ results++;

it('handles errors', function (done) {
var errored = false;
cypher('invalid query')
.on('data', function (data){
console.log(data);
})
.on('error', function (error) {
errored = true;
error.statusCode.should.eql(400);
})
.on('end', function() {
errored.should.be.true;
done();
})
;
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc