@@ -47,11 +47,11 @@ session
4747 .subscribe ({
4848 onNext : function (record ) {
4949 console .log (record);
50- },
50+ },
5151 onCompleted : function () {
5252 // Completed!
5353 session .close ();
54- },
54+ },
5555 onError : function (error ) {
5656 console .log (error);
5757 }
@@ -72,6 +72,31 @@ session
7272 .catch (function (error ) {
7373 console .log (error);
7474 });
75+
76+ // run statement in a transaction
77+ var tx = session .beginTransaction ();
78+ tx .run (" CREATE (alice {name : {nameParam} })" , { nameParam: ' Alice' }" );
79+ tx.run(" MATCH (alice {name : {nameParam} }) RETURN alice .age " , { nameParam:'Alice'}" );
80+ // decide if the transaction should be committed or rolled back
81+ var success = ...
82+ ...
83+ if (success) {
84+ tx .commit ()
85+ .subscribe ({
86+ onCompleted : function () {
87+ // Completed!
88+ session .close ();
89+ },
90+ onError : function (error ) {
91+ console .log (error);
92+ }
93+ });
94+ } else {
95+ // transaction is rolled black nothing is created in the database
96+ tx .rollback ();
97+ }
98+
99+
75100```
76101
77102## Building
@@ -89,25 +114,25 @@ See files under `examples/` on how to use.
89114This runs the test suite against a fresh download of Neo4j.
90115Or ` npm test ` if you already have a running version of a compatible Neo4j server.
91116
92- For development, you can have the build tool rerun the tests each time you change
117+ For development, you can have the build tool rerun the tests each time you change
93118the source code:
94119
95120 gulp watch-n-test
96121
97122### Testing on windows
98- Running tests on windows requires PhantomJS installed and its bin folder added in windows system variable ` Path ` .
99- To run the same test suite, run ` .\runTest.ps1 ` instead in powershell with admin right.
100- The admin right is required to start/stop Neo4j properly as a system service.
123+ Running tests on windows requires PhantomJS installed and its bin folder added in windows system variable ` Path ` .
124+ To run the same test suite, run ` .\runTest.ps1 ` instead in powershell with admin right.
125+ The admin right is required to start/stop Neo4j properly as a system service.
101126While there is no need to grab admin right if you are running tests against an existing Neo4j server using ` npm test ` .
102127
103128## A note on numbers and the Integer type
104129The Neo4j type system includes 64-bit integer values.
105- However, Javascript can only safely represent integers between ` -(2 ` <sup >` 53 ` </sup >` - 1) ` and ` (2 ` <sup >` 53 ` </sup >` - 1) ` .
130+ However, Javascript can only safely represent integers between ` -(2 ` <sup >` 53 ` </sup >` - 1) ` and ` (2 ` <sup >` 53 ` </sup >` - 1) ` .
106131In order to support the full Neo4j type system, the driver includes an explicit Integer types.
107132Any time the driver recieves an Integer value from Neo4j, it will be represented with the Integer type by the driver.
108133
109134### Write integers
110- Number written directly e.g. ` session.run("CREATE (n:Node {age: {age}})", {age: 22}) ` will be of type ` Float ` in Neo4j.
135+ Number written directly e.g. ` session.run("CREATE (n:Node {age: {age}})", {age: 22}) ` will be of type ` Float ` in Neo4j.
111136To write the ` age ` as an integer the ` neo4j.int ` method should be used:
112137
113138``` javascript
0 commit comments