forked from fabiorogeriosj/example-node-cassandra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions.js
More file actions
61 lines (61 loc) · 1.68 KB
/
actions.js
File metadata and controls
61 lines (61 loc) · 1.68 KB
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
module.exports = {
InsertContact : function (req, res, client){
client.connect(function(err, keyspace){
if(err){
throw(err);
} else {
var post = req.body;
client.execute("INSERT INTO contact (email, name, phone, address, city) VALUES (?,?,?,?,?)", [post.email, post.name, post.phone, post.address, post.city], function(err, results){
res.redirect('/');
});
}
});
},
UpdateContact : function (req, res, client){
client.connect(function(err, keyspace){
if(err){
throw(err);
} else {
var post = req.body;
client.execute("UPDATE contact SET name = ?, phone = ?, address = ?, city = ? WHERE email = ?", [post.name, post.phone, post.address, post.city, post.contactEdit], function(err, results){
res.redirect('/');
});
}
});
},
DeleteContact : function (req, res, client){
client.connect(function(err, keyspace){
if(err){
throw(err);
} else {
var post = req.body;
client.execute("DELETE FROM contact WHERE email = ?", [post.contactDel], function(err, results){
res.redirect('/');
});
}
});
},
LoadContacts : function (req, res, client){
client.connect(function(err, keyspace){
if(err){
throw(err);
} else {
var post = req.body;
var query = "SELECT * FROM contact";
if(typeof(req.query.email) != "undefined"){
query += " WHERE email = '"+req.query.email+"'";
}
client.execute(query, [], function(err, results){
var data = [];
results.rows.forEach(function(row){
if( row ){
var obj = row;
data.push(obj);
}
});
res.send(data);
});
}
});
}
}