1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | var neo4j = require('neo4j');
|
21 |
|
22 | var statement = ['MERGE (alice:Person {name:{name_a},age:{age_a}})',
|
23 | 'MERGE (bob:Person {name:{name_b},age:{age_b}})',
|
24 | 'CREATE UNIQUE (alice)-[alice_knows_bob:KNOWS]->(bob)',
|
25 | 'RETURN alice, bob, alice_knows_bob'
|
26 | ];
|
27 |
|
28 | var params = {
|
29 | name_a: 'Alice',
|
30 | age_a: 33,
|
31 | name_b: 'Bob',
|
32 | age_b: 44
|
33 | };
|
34 |
|
35 | var driver = neo4j.driver("bolt://localhost");
|
36 |
|
37 | var streamSession = driver.session();
|
38 | var streamResult = streamSession.run(statement.join(' '), params);
|
39 | streamResult.subscribe({
|
40 | onNext: function(record) {
|
41 |
|
42 | for(var i in record) {
|
43 | console.log(i);
|
44 | console.log(record[i]);
|
45 | }
|
46 | }, onCompleted: function() {
|
47 | var summary = streamResult.summarize();
|
48 |
|
49 | console.log('');
|
50 | console.log(summary.updateStatistics.nodesCreated());
|
51 | streamSession.close();
|
52 | }, onError: function(error) {
|
53 | console.log(error);
|
54 | }
|
55 | });
|
56 |
|
57 | var promiseSession = driver.session();
|
58 | var promiseResult = promiseSession.run(statement.join(' '), params);
|
59 | promiseResult.then(function(records) {
|
60 | records.forEach(function(record) {
|
61 | for(var i in record) {
|
62 | console.log(i);
|
63 | console.log(record[i]);
|
64 | }
|
65 | });
|
66 | var summary = promiseResult.summarize();
|
67 |
|
68 | console.log('');
|
69 | console.log(summary.updateStatistics.nodesCreated());
|
70 | })
|
71 | .catch(function(error) {
|
72 | console.log(error);
|
73 | })
|
74 | .then(function(){
|
75 | promiseSession.close();
|
76 | });
|