cypher-stream
Advanced tools
Comparing version 1.0.0-alpha.1 to 1.0.0
10
index.js
@@ -1,2 +0,1 @@ | ||
'use strict'; | ||
var CypherStream = require('./CypherStream'); | ||
@@ -17,3 +16,5 @@ var neo4j = require('neo4j-driver').v1; | ||
// (user, pass) => auth || undefined | ||
/** | ||
* user -> pass -> auth | undefined | ||
*/ | ||
var auth = cond([ | ||
@@ -24,6 +25,5 @@ [unapply(all(notNil)), neo4j.auth.basic ], | ||
module.exports = function Connection(url, options) { | ||
options = options || {}; | ||
module.exports = function Connection(url, username, password) { | ||
var driver = neo4j.driver(url || 'bolt://localhost', auth(options.username, options.password)); | ||
var driver = neo4j.driver(url || 'bolt://localhost', auth(username, password)); | ||
@@ -30,0 +30,0 @@ var factory = function CypherStreamFactory(statement, parameters, options) { |
{ | ||
"name": "cypher-stream", | ||
"version": "1.0.0-alpha.1", | ||
"version": "1.0.0", | ||
"description": "Streams cypher query results in a clean format", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# cypher-stream | ||
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/codex-digital/cypher-stream?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
[![Build Status](https://travis-ci.org/codex-digital/cypher-stream.svg?branch=master)](https://travis-ci.org/codex-digital/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/codex-digital/cypher-stream.png?theme=shields.io)](https://david-dm.org/codex-digital/cypher-stream.png#info=devDependencies) [![Coverage Status](https://coveralls.io/repos/codex-digital/cypher-stream/badge.png?branch=coverage)](https://coveralls.io/r/codex-digital/cypher-stream) | ||
[![Build Status](https://travis-ci.org/codex-digital/cypher-stream.svg?branch=master)](https://travis-ci.org/codex-digital/cypher-stream) | ||
[![devDependency Status](https://david-dm.org/codex-digital/cypher-stream.png?theme=shields.io)](https://david-dm.org/codex-digital/cypher-stream.png#info=devDependencies) | ||
[![NPM version](https://badge.fury.io/js/cypher-stream.png)](http://badge.fury.io/js/cypher-stream) | ||
[![Coverage Status](https://coveralls.io/repos/github/codex-digital/cypher-stream/badge.svg?branch=master)](https://coveralls.io/github/codex-digital/cypher-stream?branch=master) | ||
[![Slack Status](https://codex-community-slackin.herokuapp.com/badge.svg)](https://codex-community-slackin.herokuapp.com) | ||
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 | ||
@@ -26,8 +15,2 @@ ``` | ||
Or, for Bolt | ||
``` | ||
npm install cypher-stream@1.0.0-alpha | ||
``` | ||
## Basic usage | ||
@@ -54,16 +37,20 @@ | ||
var errored = false; | ||
cypher('invalid query') | ||
.on('error', function (error) { | ||
cypher('invalid query') | ||
.on('error', error => { | ||
errored = true; | ||
String(error).should.equal('Error: Query failure: Invalid input \'i\': expected SingleStatement (line 1, column 1)\n"invalid query"\n ^'); | ||
error.neo4j.exception.should.equal('SyntaxException'); | ||
error.neo4j.stacktrace.should.be.an.array; | ||
error.neo4j.statusCode.should.equal(400); | ||
should.equal( | ||
error.code, | ||
'Neo.ClientError.Statement.SyntaxError' | ||
); | ||
should.equal( | ||
error.message, | ||
'Invalid input \'i\': expected <init> (line 1, column 1 (offset: 0))\n"invalid query"\n ^' | ||
); | ||
}) | ||
.on('end', function() { | ||
errored.should.be.true; | ||
.on('end', () => { | ||
should.equal(true, errored); | ||
done(); | ||
}) | ||
.resume() // need to manually start it since we have no on('data') | ||
; | ||
.resume() | ||
; | ||
}); | ||
@@ -76,3 +63,3 @@ | ||
Transactions are duplex streams that allow you to write query statements then commit or roll back the written queries. | ||
Transactions are duplex streams that allow you to write query statements and read the results. | ||
@@ -93,3 +80,3 @@ Transactions have three methods: `write`, `commit`, and `rollback`, which add queries and commit or rollback the queue respectively. | ||
A `query_statement` can either be a string or a query statement object. A query statement object consists of a `statement` property and an optional `parameters` property. Additionally, you can pass an array of either. | ||
A `query_statement` can be a string or a query statement object. A query statement object consists of a `statement` property and an optional `parameters` property. Additionally, you can pass an array of either. | ||
@@ -100,4 +87,7 @@ The following are all valid options: | ||
var transaction = cypher.transaction(); | ||
transaction.write('match (n:User) return n'); | ||
transaction.write({ statement: 'match (n:User) return n' }); | ||
transaction.write({ | ||
@@ -107,2 +97,3 @@ statement : 'match (n:User) where n.first_name = {first_name} return n', | ||
}); | ||
transaction.write([ | ||
@@ -124,6 +115,7 @@ { | ||
Alternatively, a query statement may also contain a `commit` or `rollback` property instead of calling `commit()` or `rollback()` directly. | ||
Alternatively, a query statement may contain a `commit` or `rollback` property. | ||
``` js | ||
transaction.write({ statement: 'match (n:User) return n', commit: true }); | ||
transaction.write({ | ||
@@ -146,2 +138,3 @@ statement : 'match (n:User) where n.first_name = {first_name} return n', | ||
var query = 'match (n:Test) return n limit 2'; | ||
function callback(stream) { | ||
@@ -159,4 +152,7 @@ stream | ||
} | ||
var statement = { statement: query, callback: callback }; | ||
cypher([ statement, statement ]).on('end', function () { | ||
cypher([ statement, statement ]) | ||
.on('end', function () { | ||
calls.should.equal(2); | ||
@@ -166,3 +162,4 @@ ended.should.equal(2); | ||
done(); | ||
}).resume(); | ||
}) | ||
.resume(); | ||
``` | ||
@@ -175,2 +172,3 @@ | ||
var query = 'match (n:Test) return n limit 2'; | ||
function callback(stream) { | ||
@@ -188,8 +186,14 @@ stream | ||
} | ||
var statement = { statement: query, callback: callback }; | ||
var transaction = cypher.transaction(); | ||
transaction.write(statement); | ||
transaction.write(statement); | ||
transaction.commit(); | ||
transaction.resume(); | ||
transaction.on('end', function() { | ||
@@ -196,0 +200,0 @@ calls.should.equal(2); |
@@ -13,3 +13,3 @@ 'use strict'; | ||
before(function(done) { | ||
// Travis CI is slow. Give him more time. | ||
// Travis CI is slow. Give more time. | ||
if (process.env.TRAVIS_CI) { | ||
@@ -68,3 +68,3 @@ this.timeout(5000); | ||
}) | ||
.resume() // need to manually start it since we have no on('data') | ||
.resume() | ||
; | ||
@@ -71,0 +71,0 @@ }); |
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
194
42625