npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node2neo

v0.0.8

Published

Neo4j transaction support for Node.js

Downloads

3

Readme

Node2Neo

A Node.js transaction REST API for neo4j. Node2neo uses the transaction endpoints feature of the Neo4j REST API. This reduces the traffic between the server and neo4j and allows for multiple http requests within the same transaction.

This is intended to be a building block for future modules to add advanced functionality.

NOTE: Neo4j 2.0 is required.

Installation

npm install node2neo

Usage

Connecting to the db

var db = require('node2neo').db('http://localhost:7474');

There are only five methods offered by node2neo:

  1. beginTransaction
  2. executeStatement
  3. commitTransaction
  4. removeTransaction
  5. getTransactionId (helper)

Begin Transaction

To create a transaction use the db.beginTransaction function. The statements provided to the beginTransaction function must match the required neo4j format.

var transStatement = {
  statements: [{
    statement: 'CREATE n:User RETURN n'
  }, {
    statement: 'CREATE o:Person RETURN o'
  }]
}

db.beginTransaction(transStatement, function(err, results){

})
```

You can immediately commit a transaction by passing an options variable with a commmit property

```js
db.beginTransaction(transStatement, { commit: true }, function(err, results){

})
```

The response format for an open transaction is as follows (closed transaction have a different response)

```js
response: {
  results: [{
    commit: '...commit string...',
    transaction: {expires: '...transaction timeout period...'},
    errors: []
    results: [{
      columns: ['n', 'o'],
      data: [{
        row: [{ name: 'MyNode'}, {name: 'YourNode'}]
      }]
    }]

  }]
}
```

#### Execute Statement
To perform another action in the same transaction use the execute Statement function

In order to execute a statement you will need the transaction Id or commit string.
You can use the db.getTransactionId(commitString) helper to get the transaction id from the commit string or just pass in the commit string

```js
db.executeStatement(commit, statements, function(err, results){

})
```

Transaction will expire after  aperiod of time. You can prevent a transaction from expiring by submitting an empty statements array

```js
var statemetns = {
  statements: []
}
db.executeStatement(commit, statements, function(err, results){

})
```

#### Commit a transaction
All of the statements in a transaction are not commited until the whole transaction is committed. You can optionally include some further statements at this point before committing the transaction. The result from a commit is different:


```js
db.commitTransaction(commit, [statements], function(err, results){

})

// if no statement is provided you receive tw empy arrays.
// If a statement was provided the results array would be poopulated as above
{
  "results" : [ ],
  "errors" : [ ]
}
```

#### Remove a transaction
There are two ways to undo a transaction that is in mid progress: let it timeout or tell Neo4j to remove it.

```js
db.removeTransaction(commit, function(err){

})
```

##Licence
MIT