Pretty much all of the stuff I have seen related to data queries under nodejs are writing to the console rather than returning the complete data from the function.
I am struggling to retrieve the queried data, here's what I have now but it returns nothing:
function dbGet(req,res,cb){
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('/usr/share/csServ/csdb.sqlite');
var json = []; var jrow = {};
db.each("SELECT * from sensors", function(err,row) { jrow['id'] = row.id; jrow['tstamp'] = row.tstamp; json.push(jrow);}, cb(json) );
}
dbGet(req,res,function(json){
console.log(json);
});
How can I get the data into my callback and how can I close the db db.close() in the dbGet() function as I don't know when the each loop is completed ?