I'm using sqlite3 in node.js and want to make functions which return specific data.
Here is an example where a function returns the last inserted row id.
The id is correctly retrieved, and I can output it in console.log
, but how do I get its value back into my function so I can return it?
All the examples I find merely output the value here with console.log
.
_getLastInsertRowId = function () {
var id = 0;
var that = this;
db.get("SELECT last_insert_rowid() as id", function (err, row) {
id = row['id'];
//that.id = row['id']; //DOESN'T WORK
console.log(id); // shows correct id
//return row['id']; //DOESN'T WORK
});
return id; // DOESN'T WORK, ID IS ALWAYS 0
}