Skip to content

Commit 4aff373

Browse files
committed
example code doesn't work without v1
having two different ways to create a driver instance is confusing
1 parent c258354 commit 4aff373

File tree

1 file changed

+40
-31
lines changed

1 file changed

+40
-31
lines changed

README.md

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bower install neo4j-driver
1414
```
1515

1616
```javascript
17-
var neo4j = require('neo4j-driver');
17+
var neo4j = require('neo4j-driver').v1;
1818
```
1919

2020
## Include in web browser
@@ -28,7 +28,7 @@ We build a special browser version of the driver, which supports connecting to N
2828
This will make a global `neo4j` object available, where you can access the `v1` API at `neo4j.v1`:
2929

3030
```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"));
3232
```
3333

3434
## Usage examples
@@ -44,10 +44,10 @@ var session = driver.session();
4444

4545
// Run a Cypher statement, reading the result in a streaming manner as records arrive:
4646
session
47-
.run("MATCH (alice {name : {nameParam} }) RETURN alice.age", { nameParam:'Alice' })
47+
.run("MERGE (alice:Person {name : {nameParam} }) RETURN alice.name", { nameParam:'Alice' })
4848
.subscribe({
4949
onNext: function(record) {
50-
console.log(record);
50+
console.log(record._fields);
5151
},
5252
onCompleted: function() {
5353
// Completed!
@@ -61,43 +61,52 @@ session
6161
// or
6262
// the Promise way, where the complete result is collected before we act on it:
6363
session
64-
.run("MATCH (alice {name : {nameParam} }) RETURN alice.age", { nameParam:'Alice' })
64+
.run("MERGE (james:Person {name : {nameParam} }) RETURN james.name", { nameParam:'James' })
6565
.then(function(result){
6666
result.records.forEach(function(record) {
67-
console.log(record);
67+
console.log(record._fields);
6868
});
69-
7069
// Completed!
7170
session.close();
7271
})
7372
.catch(function(error) {
7473
console.log(error);
7574
});
7675

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+
}
101110
```
102111

103112
## Building

0 commit comments

Comments
 (0)