OK, I am using Objection.js to handle some database stuffs with node.js
I know that the error I am getting is common to someone learning how to use async functions, but I just cant seem to get this to work right. My async function is returning something before it finishes the query (i think)
async function getStatusSensor() {
const sensors = await StatusSensor.query()
.select('*').limit(1)
var sensor = sensors[0]
console.log(sensor.monitor + " from function")
console.log(sensor.status_type + " from function")
return sensor;
}
const sensor = getStatusSensor()
console.log(sensor.monitor)
console.log(sensor.status_type)
and the results that I get look like this
undefined
undefined
3957b from function
20GPSChadsCtrl from function
So that I can only operate on the returned row within the function that queried it. What I am after is a simple async function that I can call just to get a particular row from a database. thanks for any help!