I am trying to call simple view and within that I am making another query with the data from the view.
My problem is that I do not get it working ( this only gives me empty objects like this [{},{},{},{},{},{},{},{},{},{},{},{},{},{}]
any idea would be nice
My Code:
import { NextApiRequest, NextApiResponse } from 'next';
import { getConnection } from '../../../database/connection';
import { Song, Songs } from '../../../utils/song';
export default async function getPeople(req: NextApiRequest, res: NextApiResponse) {
const connection = getConnection()
connection.query("SELECT * FROM view3", (err: any, rows: Song[], _fields: any) => {
if (err) {
console.log(err)
res.json({err: err})
connection.destroy();
} else {
const response = rows.map( async(row:Song) => {
const getIp = async() =>{
connection.query(`SELECT * FROM user WHERE ((ip = 12.12.142.91}) AND (item = ${row.id}))`,(err:any, rows:any, _fields:any) => {
if(err){
console.log(err)
}
else{
console.log(rows)
return rows;
}
})
}
return { voted: getIp(), id: row.id, vote: row.votes,}
})
res.status(200).json(response)
connection.destroy();
}
})
}
question from:
https://stackoverflow.com/questions/66052357/async-inside-async-function-bug 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…