I expect only one result from this mySQL query.
Is it possible to fetch the result into vars without a forEach
?
pmSql.query("SELECT name FROM sqlTable LIMIT 1", function(err, rows, fields) {
rows.forEach(function(row) { // don't want this forEach, I expect only 1
console.log(row.name); // it's only one!
});
});
sure,
instead of forEach, you can try as shown below
if(rows.length == 1) {
var row = rows[0];
}
and if you are damn sure about, the result is one, then you can avoid the if check