Answer the question
In order to leave comments, you need to log in
Why is the promise resolve empty?
Good afternoon. Please tell me why the promise response is empty?
const bet = req.body.bet
const creator_id = req.user
let company_id
const company_data = new Promise(async(resolve,reject) => {
await pool.query(`select * from the_company where creator_id = ?`, {creator_id}, (error,results,fields) => {
const id = results.map(r => r.id)
const name = results.map(r => r.name) //Ответ - { id: '41' } - id
console.log(`${id} - id`)
resolve(id)
})
})
company_data.then(r => {
console.log(r) //Ответ - []
})
Answer the question
In order to leave comments, you need to log in
query method in pool async function or promise? What does she return? Why did you even want to use await/async here?
const company_data = () => new Promise((resolve,reject) => {
pool.query(`select * from the_company where creator_id = ?`, {creator_id}, (error,results,fields) => {
const id = results.map(r => r.id)
const name = results.map(r => r.name) //Ответ - { id: '41' } - id
console.log(`${id} - id`)
resolve(id)
})
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question