@@ -14,7 +14,7 @@ bower install neo4j-driver
14
14
```
15
15
16
16
``` javascript
17
- var neo4j = require (' neo4j-driver' );
17
+ var neo4j = require (' neo4j-driver' ). v1 ;
18
18
```
19
19
20
20
## Include in web browser
@@ -28,7 +28,7 @@ We build a special browser version of the driver, which supports connecting to N
28
28
This will make a global ` neo4j ` object available, where you can access the ` v1 ` API at ` neo4j.v1 ` :
29
29
30
30
``` javascript
31
- var driver = neo4j .v1 . driver (" bolt://localhost" , neo4j .auth .basic (" neo4j" , " neo4j" ));
31
+ var driver = neo4j .driver (" bolt://localhost" , neo4j .auth .basic (" neo4j" , " neo4j" ));
32
32
```
33
33
34
34
## Usage examples
@@ -44,10 +44,10 @@ var session = driver.session();
44
44
45
45
// Run a Cypher statement, reading the result in a streaming manner as records arrive:
46
46
session
47
- .run (" MATCH (alice {name : {nameParam} }) RETURN alice.age " , { nameParam: ' Alice' })
47
+ .run (" MERGE (alice:Person {name : {nameParam} }) RETURN alice.name " , { nameParam: ' Alice' })
48
48
.subscribe ({
49
49
onNext : function (record ) {
50
- console .log (record);
50
+ console .log (record . _fields );
51
51
},
52
52
onCompleted : function () {
53
53
// Completed!
@@ -61,43 +61,52 @@ session
61
61
// or
62
62
// the Promise way, where the complete result is collected before we act on it:
63
63
session
64
- .run (" MATCH (alice {name : {nameParam} }) RETURN alice.age " , { nameParam: ' Alice ' })
64
+ .run (" MERGE (james:Person {name : {nameParam} }) RETURN james.name " , { nameParam: ' James ' })
65
65
.then (function (result ){
66
66
result .records .forEach (function (record ) {
67
- console .log (record);
67
+ console .log (record . _fields );
68
68
});
69
-
70
69
// Completed!
71
70
session .close ();
72
71
})
73
72
.catch (function (error ) {
74
73
console .log (error);
75
74
});
76
75
77
- // run statement in a transaction
78
- var tx = session .beginTransaction ();
79
- tx .run (" CREATE (alice {name : {nameParam} })" , { nameParam: ' Alice' });
80
- tx .run (" MATCH (alice {name : {nameParam} }) RETURN alice.age" , { nameParam: ' Alice' });
81
- // decide if the transaction should be committed or rolled back
82
- var success = ...
83
- ...
84
- if (success) {
85
- tx .commit ()
86
- .subscribe ({
87
- onCompleted : function () {
88
- // Completed!
89
- session .close ();
90
- },
91
- onError : function (error ) {
92
- console .log (error);
93
- }
94
- });
95
- } else {
96
- // transaction is rolled black nothing is created in the database
97
- tx .rollback ();
98
- }
99
-
100
-
76
+ // run statement in a transaction
77
+ var tx = session .beginTransaction ();
78
+ tx .run (" MERGE (bob:Person {name : {nameParam} }) RETURN bob.name" , { nameParam: ' Bob' })
79
+ .subscribe ({
80
+ onNext : function (record ) {
81
+ console .log (record ._fields );
82
+ },
83
+ onCompleted : function () {
84
+ // Completed!
85
+ session .close ();
86
+ },
87
+ onError : function (error ) {
88
+ console .log (error);
89
+ }
90
+ });
91
+
92
+ // decide if the transaction should be committed or rolled back
93
+ var success = false ;
94
+
95
+ if (success) {
96
+ tx .commit ()
97
+ .subscribe ({
98
+ onCompleted : function () {
99
+ // Completed!
100
+ },
101
+ onError : function (error ) {
102
+ console .log (error);
103
+ }
104
+ });
105
+ } else {
106
+ // transaction is rolled black and nothing is created in the database
107
+ console .log (' rolled back' );
108
+ tx .rollback ();
109
+ }
101
110
```
102
111
103
112
## Building
0 commit comments