forked from anmolagrwl/neo4j-pubnub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index-crud.js
141 lines (130 loc) · 3.27 KB
/
index-crud.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
var db = require("seraph")
var pubnub = require("pubnub")({
subscribe_key: 'demo', // always required
publish_key: 'demo' // only required if publishing
});
var mumbai, delhi, train;
// Creating a node with a label
// --------------------------------
// function create_node() {
// db.save({ name: 'Delhi' }, 'City', function(err, node) {
// if (err) throw err;
// console.log(node.name);
// delhi = (node.name);
// });
//
// db.save({ name: 'Mumbai' }, 'City', function(err, node) {
// if (err) throw err;
// console.log(node.name);
// mumbai = (node.name);
// });
//
// db.save({ name: 'train-1', 'available-seats': 50 }, 'Train', function(err, node) {
// if (err) throw err;
// console.log(node.name);
// train = (node.name);
// });
// }
//
// create_node();
// Finding nodes
// ----------------
// function find_node() {
//
// mum = { name: "Mumbai" };
//
// db.find(mum, function (err, result) {
// if (err) throw err;
// // console.log(result);
// for (r of result) {
// console.log(r);
// mumbai = r;
// }
// });
//
// del = { name: "Delhi" };
//
// db.find(del, function (err, result) {
// if (err) throw err;
// // console.log(result);
// for (r of result) {
// console.log(r);
// delhi = r;
// }
// });
//
// tra = { name: "train-1" };
//
// db.find(tra, function (err, result) {
// if (err) throw err;
// // console.log(result);
// for (r of result) {
// console.log(r);
// train = r;
// }
// });
// }
//
// find_node();
// Create relationships
// -------------------------
// mumbai = { name: 'Mumbai', id: 2 }
// delhi = { name: 'Delhi', id: 1 }
// train = { name: 'train-1', 'available-seats': 50, id: 0 }
//
// function create_rel() {
// db.relate(mumbai, 'origin', train, function(err, relationship) {
// console.log(relationship);
// });
//
// db.relate(train, 'destination', delhi, function(err, relationship) {
// console.log(relationship);
// });
// }
//
// create_rel();
// Update node
// ----------------------
tra = { name: "train-1" };
function update_node() {
db.find(tra, function (err, result) {
if (err) throw err;
// console.log(result);
for (r of result) {
// console.log(r);
train = r;
}
console.log(train);
train["available-seats"]--;
db.save(train, function(err, node) {
// console.log(node);
pubnub.publish({
channel: 'neo4j',
message: {"seats_left": node["available-seats"]},
callback: function(m){console.log(m)}
});
return node["available-seats"];
})
});
}
update_node();
//
// function find_seats() {
// db.find(tra, function (err, result) {
// if (err) throw err;
// var train;
// // console.log(result);
// for (r of result) {
// // console.log(r);
// train = r;
// console.log(train["available-seats"]);
// return train["available-seats"];
// }
// // console.log(train);
// });
// }
// find_seats();
// START n = node(*)
// OPTIONAL MATCH n-[r]-()
// WHERE (ID(n)>0 AND ID(n)<10000)
// DELETE n, r;