I'm trying to do something like this:
var query = 'select max(count) from ' + series +
' where value = \'' + search + '\'';
if (db.query(query, callback) !== undefined) {
return callback;
} else {
return callback = [{
name: series,
columns: ['time', 'max'],
points: [
[0, 0]
]
}];
}
I'm trying to verify if that query is undefined or the element searched doesn't exist in the influxdb, and then arm a callback just like if the element exist, the if sentence works, but the else return an empty array
The db parameter is where are the data base configurations.
EDIT:
Thanks Osukaa for your answe. I try what you sugest but don't have response. Here is the complete function with your changes:
var counter = function (config, callback) {
var count = 'select max(count) from ' + series + ' where value = \'' + search + '\'';
db.query(count, function (err, res) {
if(err) return err;
if(res.length == 0){
return [{
name: series,
columns: ['time', 'max'],
points: [
[0, 0]
]
}];
}else{
return res;
}
});
};
The console.log shows an empty array.
EDIT 2:
Thanks @Osukaa, unfortunately that don't work, this is the error that returns:
Debug: handler, error {"msec":395.7593630000483,"error":"Couldn't find series: items.type.updated"} Debug: internal, error Error: Couldn't find series: items.type.updated
Thanks.
Aucun commentaire:
Enregistrer un commentaire