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
EDIT 3:
I've solved the problem when try to create a series. When the series don't exist, show this error 'Error Couldn't find series [series name]', so I put this code in the error code:
db.query(qCount, function(err, res) {
if (err) {
if (err == 'Error: Couldn\'t find series: ' + name.series) {
res = newSeries;
return callback(null, res);
} else {
return callback(err);
}
} else {
if (res.length !== 0) {
return callback(null, res);
} else {
res = newSeries;
return callback(null, res);
}
}
});
When the error is equal to 'Error: Couldn\'t find series: ' + name.series, I pass the values to create them.
Thanks.
Aucun commentaire:
Enregistrer un commentaire