All Projects → codex-digital → Cypher Stream

codex-digital / Cypher Stream

Neo4j Cypher queries as Node.js object streams

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Cypher Stream

godsend
A simple and eloquent workflow for streaming messages to micro-services.
Stars: ✭ 15 (-74.14%)
Mutual labels:  stream, streams, streaming-api
Node Neo4j
[RETIRED] Neo4j graph database driver (REST API client) for Node.js
Stars: ✭ 935 (+1512.07%)
Mutual labels:  cypher, neo4j
Stream Splicer
streaming pipeline with a mutable configuration
Stars: ✭ 52 (-10.34%)
Mutual labels:  stream, streams
Streamjs
Lazy Object Streaming Pipeline for JavaScript
Stars: ✭ 858 (+1379.31%)
Mutual labels:  streaming-api, stream
Nuclear
Streaming music player that finds free music for you
Stars: ✭ 7,133 (+12198.28%)
Mutual labels:  stream, streaming
Sql Streams
Painless low level jdbc abstraction using the java 8 stream api.
Stars: ✭ 17 (-70.69%)
Mutual labels:  stream, streams
R2d2 Cypher
Cypher support for the r2d2 connection pool
Stars: ✭ 8 (-86.21%)
Mutual labels:  cypher, neo4j
Neo4j Python Driver
Neo4j Bolt driver for Python
Stars: ✭ 607 (+946.55%)
Mutual labels:  cypher, neo4j
Scala Cypher Dsl
A type-safe Cypher Query Language DSL for Scala.
Stars: ✭ 34 (-41.38%)
Mutual labels:  cypher, neo4j
Taliesin
Lightweight audio streaming server
Stars: ✭ 35 (-39.66%)
Mutual labels:  streaming-api, streaming
Saber
Window-Based Hybrid CPU/GPU Stream Processing Engine
Stars: ✭ 35 (-39.66%)
Mutual labels:  stream, streaming
Neovis.js
Neo4j + vis.js = neovis.js. Graph visualizations in the browser with data from Neo4j.
Stars: ✭ 748 (+1189.66%)
Mutual labels:  cypher, neo4j
Neo4j Graph Algorithms
Efficient Graph Algorithms for Neo4j
Stars: ✭ 713 (+1129.31%)
Mutual labels:  cypher, neo4j
Chunk Store Stream
Convert an abstract-chunk-store compliant store into a readable or writable stream
Stars: ✭ 24 (-58.62%)
Mutual labels:  stream, streams
Membrane core
The core of the Membrane Framework, advanced multimedia processing framework
Stars: ✭ 662 (+1041.38%)
Mutual labels:  streaming-api, streaming
Remote Web Streams
Web streams that work across web workers and iframes.
Stars: ✭ 26 (-55.17%)
Mutual labels:  stream, streams
Neo4j Helm
Helm Charts for running Neo4j on Kubernetes
Stars: ✭ 43 (-25.86%)
Mutual labels:  cypher, neo4j
Lol Html
Low output latency streaming HTML parser/rewriter with CSS selector-based API
Stars: ✭ 566 (+875.86%)
Mutual labels:  stream, streaming
Neo4j Graphql Js
A GraphQL to Cypher query execution layer for Neo4j and JavaScript GraphQL implementations.
Stars: ✭ 585 (+908.62%)
Mutual labels:  cypher, neo4j
Soundwaveinteractive
Interactive Sound Board for Mixer. Microsoft shut Mixer down, so this application no longer works. RIP Mixer.
Stars: ✭ 27 (-53.45%)
Mutual labels:  stream, streaming

cypher-stream

Build Status devDependency Status NPM version Coverage Status Slack Status

Neo4j cypher queries as node object streams.

Installation

npm install cypher-stream

Basic usage

var cypher = require('cypher-stream')('bolt://localhost', 'username', 'password');

cypher('match (user:User) return user')
  .on('data', function (result){
    console.log(result.user.first_name);
  })
  .on('end', function() {
    console.log('all done');
  })
;

Handling errors

var cypher = require('cypher-stream')('bolt://localhost', 'username', 'password');
var should = require('should');
it('handles errors', function (done) {
  var errored = false;
    cypher('invalid query')
    .on('error', error => {
      errored = true;
      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', () => {
      should.equal(true, errored);
      done();
    })
    .resume()
    ;
});

Transactions

Transactions are duplex streams that allow you to write query statements and read the results.

Transactions have three methods: write, commit, and rollback, which add queries and commit or rollback the queue respectively.

Creating a transaction

var transaction = cypher.transaction(options)

Adding queries to a transaction

transaction.write(query_statement);

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.

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({
  statement  : 'match (n:User) where n.first_name = {first_name} return n',
  parameters : { first_name: "Bob" }
});

transaction.write([
  {
    statement  : 'match (n:User) where n.first_name = {first_name} return n',
    parameters : { first_name: "Bob" }
  },
  'match (n:User) where n.first_name = {first_name} return n'
]);

Committing or rolling back

transaction.commit();
transaction.rollback();

Alternatively, a query statement may contain a commit or rollback property.

transaction.write({ statement: 'match (n:User) return n', commit: true });

transaction.write({
  statement  : 'match (n:User) where n.first_name = {first_name} return n',
  parameters : { first_name: "Bob" },
  commit     : true
});

Stream per statement

To get a stream per statement, just pass a callback function with the statement object. This works for regular cypher calls and transactions.

var results = 0;
var calls   = 0;
var ended   = 0;
var query   = 'match (n:Test) return n limit 2';

function callback(stream) {
  stream
    .on('data', function (result) {
      result.should.eql({ n: { test: true } });
      results++;
    })
    .on('end', function () {
      ended++;
    })
  ;
  calls++;
}

var statement = { statement: query, callback: callback };

cypher([ statement, statement ])
.on('end', function () {
  calls.should.equal(2);
  ended.should.equal(2);
  results.should.equal(4);
  done();
})
.resume();
var results = 0;
var calls   = 0;
var ended   = 0;
var query   = 'match (n:Test) return n limit 2';

function callback(stream) {
  stream
    .on('data', function (result) {
      result.should.eql({ n: { test: true } });
      results++;
    })
    .on('end', function () {
      ended++;
    })
  ;
  calls++;
}

var statement = { statement: query, callback: callback };
var transaction = cypher.transaction();

transaction.write(statement);

transaction.write(statement);

transaction.commit();

transaction.resume();

transaction.on('end', function() {
  calls.should.equal(2);
  ended.should.equal(2);
  results.should.equal(4);
  done();
});

Unsafe Integers

Unsafe integers* are returned as strings. If your system deals with particularly large or small numbers, this will require special handling.

See "A note on numbers and the Integer type" on the neo4j-javascript-driver README for more information.

* Unsafe integers are any integers greater than Number.MAX_SAFE_INTEGER or less than Number.MIN_SAFE_INTEGER.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].