In the following code, how do I make the variable songlist available to the callback function complete?
If I run the code as is, sqlite successfully populates the songlist, but when the callback is run the variable becomes null.
Basically, I'm trying to figure out a way to ensure sqlite completes running before console.log(songlist) runs. I thought using a callback would do it, but then run into this variable passing issue. Thanks.
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('mydb.db');
var songlist = []
var complete = function (songlist) {
console.log(songlist);
}
db.serialize(function () {
db.each("SELECT rowid AS id, info FROM lorem where info like '%" + song + "%'", function (err, row) {
songlist.push(row.info);
console.log("each")
}, complete)
})