Created
July 16, 2015 16:20
-
-
Save TrevorBasinger/ffea6e82945d730fd673 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const | |
_ = require ('helpers').http, | |
R = require ('ramda'), | |
T = require ('data.task'), | |
M = require ('control.monads'), | |
mysql = require ('mysql'), | |
Q = require ('query-builder'), | |
C = require ('cassandra-driver'), | |
moment = require ('moment'), | |
sql = Q.drivers.mysql, | |
conf = { host: 'localhost', database: 'scada', dateStrings: true }, | |
//buildQueryFromRequest :: Req -> String | |
buildQueryFromRequest = R.pipe ( Q.param.parseReq | |
, R.apply (Q.query (sql).mkSelect)), | |
//resourceQuery :: Req -> Task [Resource] | |
resourceQuery = R.compose (sql.query (conf), buildQueryFromRequest), | |
nil = null; | |
module.exports = function (app, io) { | |
app.get ('/v3/scada/resource/:resource', | |
_.runResponseTask (_.sendError, _.sendJson, resourceQuery)); | |
app.get ('/v3/scada/unithistory/:id', function (req, res) { | |
var client = new C.Client ({ contactPoints: [ '172.16.98.116' | |
, '172.16.98.118' | |
, '172.16.98.117' ] | |
, keyspace: 'scada' }), | |
qry = 'select * from unit_sensor where id = 9566 and sensor = 22 and year = 2015;'; | |
client.execute (qry, [], function (err, d) { | |
if (err) { log (err); return res.send (err); } | |
R.length (d.rows); | |
res.json (d.rows); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment