I'm having a problem with seemingly textbook example of SQlite usage:
Code below
const db_client = new sqlite3.Database(HISTORY_DB, (err) => {
if (err) {
console.error(err.message, '## ERROR ##');
return;
}
console.log('Connected to the SQlite DB');
});
const current_hour = new Date().getHours();
const sql = `SELECT value FROM history where hour = ${current_hour}`;
const getSql = async (sql) => {
await db_client.get(sql, [], (err, row) => {
if (err) {
return console.error(err.message);
}
console.log(row.value, 'FIRST');
return parseInt(row.value);
})
};
console.log(await getSql(sql), 'SECOND');
For some reason I cannot get the value of the sql response. I've tried a couple of approaches and its always undefined, but console.log works. I cannot figure it out.
Console log pasted below:
undefined SECOND
Connected to the SQlite DB
287439002531265 FIRST