I'm trying to query my mysql database for a value using Async/Await but my constant 'map' always returns undefined, I am not too sure why
const get_map = () =>{
db.query('SELECT game,game2 FROM battles WHERE player1=? OR player2=?',[result.char,result.char],(err,results)=>{
if(err){
return(err)
}
if(!results[0]){
return('No such battle?')
}
console.log(results[0])
return(results[0])
})
}
const proccessTurn = async ()=>{
const map = await get_map()
console.log(map)
let game = JSON.parse(map.game)
let game2 = JSON.parse(map.game2)
const char = result.char
const playerTurn = game2.turn[0]
}
The console doesn't even log
console.log(results[0])
This line so why does the await function resolve before it actually returns something? Shouldn't it wait for the returns?
Thank you for the help
{...}fromget_mapor change it toreturn db.query(...)and it should work fine.return, I think it's good enough explanation.