Neo4j transaction support for Node.js
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.
npm install node2neo
var db = require'node2neo'db'';
There are only five methods offered by node2neo:
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'dbbeginTransactiontransStatement```You can immediately commit a transaction by passing an options variable with a commmit property```jsdbbeginTransactiontransStatement commit: true```The response format for an open transaction is as follows (closed transaction have a different response)```jsresponse:results:commit: '...commit string...'transaction: expires: '...transaction timeout period...'errors:results:columns: 'n' 'o'data:row: name: 'MyNode' name: 'YourNode'```#### Execute StatementTo perform another action in the same transaction use the execute Statement functionIn 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```jsdbexecuteStatementcommit statements```Transaction will expire after aperiod of time. You can prevent a transaction from expiring by submitting an empty statements array```jsvar statemetns =statements:dbexecuteStatementcommit statements```#### Commit a transactionAll 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:```jsdbcommitTransactioncommit statements// 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 transactionThere are two ways to undo a transaction that is in mid progress: let it timeout or tell Neo4j to remove it.```jsdbremoveTransactioncommit```##LicenceMIT