|
2 | 2 | var neo4j = require('../build/node/neo4j');
|
3 | 3 |
|
4 | 4 | var statement = ['MERGE (alice:Person {name:{name_a},age:{age_a}})',
|
5 |
| - 'MERGE (bob:Person {name:{name_b},age:{age_b}})', |
6 |
| - 'CREATE UNIQUE (alice)-[alice_knows_bob:KNOWS]->(bob)', |
7 |
| - 'RETURN alice AS, bob, alice_knows_bob' |
| 5 | + 'MERGE (bob:Person {name:{name_b},age:{age_b}})', |
| 6 | + 'CREATE UNIQUE (alice)-[alice_knows_bob:KNOWS]->(bob)', |
| 7 | + 'RETURN alice, bob, alice_knows_bob' |
8 | 8 | ];
|
9 | 9 |
|
10 | 10 | var params = {
|
11 |
| - name_a: 'Alice', |
12 |
| - age_a: 33, |
13 |
| - name_b: 'Bob', |
14 |
| - age_b: 44 |
| 11 | + name_a: 'Alice', |
| 12 | + age_a: 33, |
| 13 | + name_b: 'Bob', |
| 14 | + age_b: 44 |
15 | 15 | };
|
16 | 16 |
|
17 | 17 | var driver = neo4j.driver("neo4j://localhost");
|
18 |
| -var session = driver.session(); |
19 | 18 |
|
20 |
| -session.run(statement.join(' '), params).subscribe({ |
21 |
| - onNext: function(record) { |
22 |
| - // On receipt of RECORD |
23 |
| - for(var i in record) { |
24 |
| - console.log(i); |
25 |
| - console.log(record[i]); |
26 |
| - } |
27 |
| - }, onCompleted: function(metadata) { |
28 |
| - // On receipt of header summary message |
29 |
| - console.log(''); |
30 |
| - console.log(metadata); |
31 |
| - }, onError: function(error) { |
32 |
| - console.log(error); |
| 19 | +var streamSession = driver.session(); |
| 20 | +streamSession.run(statement.join(' '), params).subscribe({ |
| 21 | + onNext: function(record) { |
| 22 | + // On receipt of RECORD |
| 23 | + for(var i in record) { |
| 24 | + console.log(i); |
| 25 | + console.log(record[i]); |
33 | 26 | }
|
| 27 | + }, onCompleted: function(metadata) { |
| 28 | + // On receipt of header summary message |
| 29 | + console.log(''); |
| 30 | + console.log(metadata); |
| 31 | + streamSession.close(); |
| 32 | + }, onError: function(error) { |
| 33 | + console.log(error); |
| 34 | + } |
34 | 35 | });
|
| 36 | + |
| 37 | +var promiseSession = driver.session(); |
| 38 | +promiseSession.run(statement.join(' '), params) |
| 39 | + .then(function(records){ |
| 40 | + records.forEach(function(record) { |
| 41 | + for(var i in record) { |
| 42 | + console.log(i); |
| 43 | + console.log(record[i]); |
| 44 | + } |
| 45 | + }) |
| 46 | + }) |
| 47 | + .catch(function(error) { |
| 48 | + console.log(error); |
| 49 | + }) |
| 50 | + .then(function(){ |
| 51 | + promiseSession.close(); |
| 52 | + }); |
0 commit comments