Я новичок в синтаксисе async и await. Я написал функцию, возвращающую значение, данное обещанием запроса SQLite в собственном скрипте, но возвращаемое значение - [обещание объекта] при записи в консоль. Код идет ниже
async function counterChanger(database) {
await database.all("SELECT * FROM pets").then(function (rows) {
for (row in rows) {
// console.log(rows[row]);
counter += 1;//counter is a global variable
}
return counter;
}).then(function (counter) {
counterValue = counter; //counterValue is a global variable initialized to 0
})
console.log("Outside db counterValue is ", counterValue); //meanwhile the console displays the actual value of ounterValue
return counterValue; // the output is [Object promise] instead of the value of counterValue
}