I am trying to query sqlite3 from node function. Depending on result it should return TRUE or FALSE back to the calling code. This is what I have done, but always get 'undefined':
var sqlite3 = require("sqlite3").verbose();
var dbOpen = function dbOpen() {
sqlite3 = require('sqlite3').verbose();
db = new sqlite3.Database('./internaldb/OPMSE.db');
}
module.exports.dbOpen = dbOpen;
dbOpen();
mKey = 'AIzaSyCrIYuHJ_jiZqmGYoAs7mxiloB3-OBx5WI';
async function db1() {
function db2() {
db.each("SELECT STATUS status FROM API_Keys WHERE KEY = ? AND STATUS = ?", [mKey, '1'], (err, row, x) => {
var keyValid = false;
if (err) {
console.log('There is an error in API Validation')
} else {
console.log(keyValid + '<--This is from upper fun')
keyValid = true;
return keyValid;
}
db.close();
return keyValid;
});
} // db2
d = await db2();
console.log(d + '<--Supposed to return TRUE or FALSE')
} //db1
x = db1();
console.log(x)
/*Returns:
Promise { <pending> }
undefined<--Supposed to return TRUE or FALSE
false<--This is from upper fun
*/