I am currently working on a project where I need to fetch data from MySQL, map through the array returned, and send out tweets based on certain criteria. However, my current code only sends a tweet for one element in the array when it should actually be sending multiple tweets as it iterates through all elements. Below is the snippet of my code:
array.items.map(item => {
con.query(`SELECT username FROM users where country="${item.country}"`, async function (err, result, fields) {
if (err) throw err;
console.log(result);
result.length > 0 && result.map(async user => {
try {
await sendTweet(`Hello ${user.username}, your selected country is ${item.country}`);
} catch (error) {
console.error(error.body)
return false
}
})
});
});
I seem to be having trouble with this logic. Any guidance or help would be greatly appreciated. Thank you.