'How to write a function that returns InfluxDb2 data?
The example that the InfluxDb2 documentation provides for reading data is the following:
const queryApi = new InfluxDB({url, token}).getQueryApi(org);
const fluxQuery = '<flux query>';
const fluxObserver = {
next(row, tableMeta) {
const o = tableMeta.toObject(row)
console.log(`${o._time} ${o._measurement}: ${o._field}=${o._value}`);
}
}
queryApi.queryRows(fluxQuery, fluxObserver)
This reads the data and prints it row by row to the console.
But how to write a function that gives the data as a return value? Something like this:
function () {
const queryApi = new InfluxDB({url, token}).getQueryApi(org);
const fluxQuery = '<flux query>';
var result = [];
const fluxObserver = {
next(row, tableMeta) {
const o = tableMeta.toObject(row)
result.push(o._value);
}
}
queryApi.queryRows(fluxQuery, fluxObserver)
return result; // this does not work
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
