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 🙏

© 2025 – Pkg Stats / Ryan Hefner

node2neo-transactions

v0.0.3

Published

Transaction wrapper for Node2Neo

Readme

Node2Neo

Transasction wrapper for Node2Neo queries Transactions allow the creation of multiple Node2Neo transactions. Transactions store cypher statements in case of an error and store events to be triggered once the transaction has been successfully committed.

Transactions are useful when you have multiple separate items to create but want an "all-or-nothing" commital approach in the database. For example event nodes are a good way of tracking changes to a node over time. Every change that is created you create a new event node and link it via a relationship to the updated node. In this instance you have to update the original node, create a new event node, create a relationship between teh two, update other existing relationships and potentially more. Transactions are useful in this and other use cases.

Transaction.begin

var db = require('node2neo')('http://localhost:7474')
var Transaction = require('node2neo-transaction');

var trans1 = new Transaction(db);

trans1.begin([statement], function(err, response){
  //execute transactions
})

[statement] is optional and can be a cypher string or an object with 'statement' and 'parameters' properties. See the node2neo-model repository for transaction options.

Transaction Execution

After opening a transasction you can execute a number of statements on the transaction. These will all run and return an error or the results of the transaction. You can nest transactions, if you need the previous new node id, for example.

Using the async library is useful for running multiple items in sync or parallel.

Once all of the transactions have been applied you can commit the transaction to the database.

trans1.begin(function(err, response){
  if(err) return callback(err)
  async.parallel([
    function(cb){
      User.create(userData, {transaction: trans1}, function(err, response){
        if(err) return cb(err);
        var relationship = {
          indexKey: '_id',
          indexValue: response._id, //The id of the node you are interested in.
          nodeLabel: 'User',
          direction: 'from',
          type: 'FRIEND'
        }
        Event.create(eventData, {relationship: relationship, transaction: trans1}, cb);
      });
    },
    function(cb){
      Other.create...
    }],
    function(err, results){
      if(err) return callback(err);
      trans1.commit(function(err, results){
        if(err) return callback(err);
        // do something...
        //all of the statements will have been executed correctly or rolled back.
      });
    }
  );
});

Transaction Commit

After you have opened a transaction and have applied all of the statements you can commit the transaction.

trans1.commit(function(err, response){
  // if any of the statements have produced an error they will be returned here.
  if(err) return callback(err);
  //do something...
});

Transaction Removal

Transactions automatically expire after a period of time. If you want to remove a transaction before this time you can explicitly remove it.

trans1.remove(function(err){
  return callback(err)
})

##Licence MIT