I'm running into a small problem while trying to get data out of a sqlite database to a string. Here is the code:
router.get('/', function(req, res) {
var db = req.db;
var thisShouldWork = 'Hmmm';
db.all('select rowid as id, value from test', function(err, rows) {
rows.forEach(function(row){
console.log(row.id + ": " + row.value);
thisShouldWork += 'Heeee';
});
});
thisShouldWork += 'What?';
console.log(thisShouldWork.toString());
res.send(thisShouldWork);
});
The variable 'thisShouldWork' just outputs 'HmmmWhat?' at the end of this code, while it should have a few 'Heeee's in there as well. Also, console.log prints 3 lines of data so the for loop is definitely executing. Am I doing something wrong without realizing or is there a different/better way to achieve the same thing?