-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.js
More file actions
31 lines (27 loc) · 1.01 KB
/
data.js
File metadata and controls
31 lines (27 loc) · 1.01 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
module.exports = function(app,cli){
app.get('/data/:keyspace/:table', function(req, res){
console.log('get data for',req.params.keyspace, req.params.table)
if(req.params.keyspace != null && req.params.table != null) {
var q = "select * from "+req.params.keyspace+"."+req.params.table
if( JSON.stringify(req.query) !== JSON.stringify({})) {
console.log(JSON.stringify(req.query))
q += " WHERE "
for(k in req.query) {
q += k + "=" + req.query[k] + ""
}
}
q += " ;"
console.log("executing",q)
cli.execute(q,function(err,resp){
if(err){
console.log(err)
res.json({"error":11,"message":JSON.stringify(err)})
} else {
res.json({"error":0,"result":resp.rows})
}
})
} else {
res.json({"error":10,"message":"no keyspace or table specified"})
}
})
}