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 = [
|
23 | 'MERGE (alice:Person {name:{name_a},age:{age_a}})',
|
24 | 'MERGE (bob:Person {name:{name_b},age:{age_b}})',
|
25 | 'CREATE UNIQUE (alice)-[alice_knows_bob:KNOWS]->(bob)',
|
26 | 'RETURN alice, bob, alice_knows_bob'
|
27 | ]
|
28 |
|
29 | var params = {
|
30 | name_a: 'Alice',
|
31 | age_a: 33,
|
32 | name_b: 'Bob',
|
33 | age_b: 44
|
34 | }
|
35 |
|
36 | var driver = neo4j.driver('bolt://localhost')
|
37 |
|
38 | var streamSession = driver.session()
|
39 | var streamResult = streamSession.run(statement.join(' '), params)
|
40 | streamResult.subscribe({
|
41 | onNext: function (record) {
|
42 |
|
43 | for (var i in record) {
|
44 | console.log(i)
|
45 | console.log(record[i])
|
46 | }
|
47 | },
|
48 | onCompleted: function () {
|
49 | var summary = streamResult.summarize()
|
50 |
|
51 | console.log('')
|
52 | console.log(summary.updateStatistics.nodesCreated())
|
53 | streamSession.close()
|
54 | },
|
55 | onError: function (error) {
|
56 | console.log(error)
|
57 | }
|
58 | })
|
59 |
|
60 | var promiseSession = driver.session()
|
61 | var promiseResult = promiseSession.run(statement.join(' '), params)
|
62 | promiseResult
|
63 | .then(function (records) {
|
64 | records.forEach(function (record) {
|
65 | for (var i in record) {
|
66 | console.log(i)
|
67 | console.log(record[i])
|
68 | }
|
69 | })
|
70 | var summary = promiseResult.summarize()
|
71 |
|
72 | console.log('')
|
73 | console.log(summary.updateStatistics.nodesCreated())
|
74 | })
|
75 | .catch(function (error) {
|
76 | console.log(error)
|
77 | })
|
78 | .then(function () {
|
79 | promiseSession.close()
|
80 | })
|