node-tsguru
v1.6.1
Published
TimeSeries.Guru Node.js client
Downloads
5
Readme
node-tsguru
TimeSeries.Guru Node.js client.
Installation
npm install node-tsguru
Demos
Demo applications are available at:
- https://github.com/widdix/node-tsguru-demo
- https://github.com/widdix/node-tsguru-tinkerforge-demo
Usage
Callback style
Create client
var tsguru = require("node-tsguru");
tsguru({token: "abc123456789def", databaseID: "abc123456789def"}, function(err, client) {
if (err) throw err;
console.log("connected");
// interact with client like demonstrated below
});
Insert single value (simple time series with one column)
client.insert("sensor01", 123.45, function(err) {
if (err) throw err;
console.log("inserted");
});
Insert single value (simple time series with two columns)
client.insert("sensor01", 123.45, 100, function(err) {
if (err) throw err;
console.log("inserted");
});
Insert single value (symbol time series with one column)
client.insertSymbol("sensor", "sen01", 123.45, function(err) {
if (err) throw err;
console.log("inserted");
});
Insert single value (symbol time series with three columns)
client.insertSymbol("sensor", "sen01", 123.45, 10, true, function(err) {
if (err) throw err;
console.log("inserted");
});
Insert multiple values
client.bulk()
.add("sensor01", 123.45)
.add("sensor02", 234.56)
.add("sensor03", 345.67)
.add("sensor04", 456.78)
.insert(function(err) {
if (err) throw err;
console.log("bulk inserted");
});
Buffer values
var buffer = client.buffer({delay: 250});
buffer.on("error", function(err) {
throw err;
});
buffer.on("flushed", function() {
console.log("flushed");
});
setInterval(function() {
buffer.add("sensor01", 123.45);
}, 100);
buffer()
returns an [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
. Emitted events are error
, flush
and flushed
.
Promise style
Create client
var tsguru = require("node-tsguru");
tsguru({token: "abc123456789def", databaseID: "abc123456789def"})
.then(function(client) {
console.log("connected");
// interact with client like demonstrated below
})
.catch(function(err) {
console.log(err);
});
Insert single value
client.insert("sensor01", 123.45)
.then(function(client) {
console.log("inserted");
})
.catch(function(err) {
console.log(err);
});
Insert multiple values
client.bulk()
.add("sensor01", 123.45)
.add("sensor02", 234.56)
.add("sensor03", 345.67)
.add("sensor04", 456.78)
.insert()
.then(function(client) {
console.log("bulk inserted");
})
.catch(function(err) {
console.log(err);
});
API
(params[, cb])
params
: Objecttoken
: StringdatabaseID
: Stringtimeout
: Number in milliseconds (optional, default: 10000)
cb
: Function(err, client) (optional)err
: Error or undefinedclient
: Client or undefined
returns a Promise if no cb
was supplied
Client
Client
is an [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
.
insert(timeseriesName, value1[, value2[, ...]][, cb])
Insert into a simple time series.
timeseriesName
: Stringvalue1
...valueN
: Number, Boolean or Stringcb
: Function(err) (optional)err
: Error or undefined
returns a Promise if no cb
was supplied
insertSymbol(timeseriesName, symbol, value1[, value2[, ...]][, cb])
Insert into a symbol time series.
timeseriesName
: Stringsymbol
: Stringvalue1
...valueN
: Number, Boolean or Stringcb
: Function(err) (optional)err
: Error or undefined
returns a Promise if no cb
was supplied
bulk()
returns a Bulk
Bulk
add(timeseriesName, value1[, value2[, ...]])
Add to a simple time series.
timeseriesName
: Stringvalue1
...valueN
: Number, Boolean or String
addSymbol(timeseriesName, symbol, value1[, value2[, ...]])
Add to a symbol time series.
timeseriesName
: Stringsymbol
: Stringvalue1
...valueN
: Number, Boolean or String
insert([cb])
Insert takes care about maximal allowed body size. A single insert can be split into multiple POST calls if the HTTP body gets to large.
cb
: Function(err) (optional)err
: Error or undefined
returns a Promise if no cb
was supplied
buffer(params)
params
: Objectdelay
: Number - delay in milliseconds
returns a Buffer
Buffer
add(timeseriesName, value1[, value2[, ...]])
Add to a simple time series.
timeseriesName
: Stringvalue1
...valueN
: Number, Boolean or String
addSymbol(timeseriesName, symbol, value1[, value2[, ...]])
Add to a symbol time series.
timeseriesName
: Stringsymbol
: Stringvalue1
...valueN
: Number, Boolean or String
close([cb])
Flush the buffer and stop the interval timer. No more adds after close!
cb
: Function(err) (optional)err
: Error or undefined
returns a Promise if no cb
was supplied