-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (36 loc) · 871 Bytes
/
index.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
'use strict';
var _ = require('lodash');
var request = require('request-promise');
var Influx = function (options) {
options = options || {};
var defaults = {
host: '127.0.0.1',
port: 8086,
ssl : false,
};
options = _.merge(defaults, options);
_.assign(this, options);
var endpoint = this.ssl
? 'https://'
: 'http://' + this.host + ':' + this.port;
this._queryEndpoint = endpoint + '/query';
this._writeEndpoint = endpoint + '/write';
}
Influx.prototype.query = function(q) {
var self = this;
return request({
url : self._queryEndpoint,
qs : {
db : self.db ? self.db : undefined,
q : q
},
json: true,
})
.then(function(res) {
if (res.results[0].hasOwnProperty('error'))
throw new Error(res.results[0].error);
else
return res;
});
};
module.exports = Influx;