E
E
exdude2020-11-30 14:03:08
SQL
exdude, 2020-11-30 14:03:08

Why can't I define this query?

const getdata = (async function() {
    return {
        cities: await new Promise((res, rej) => {
            connection.query('SELECT * FROM posts', (err, result) => {
                if (err) throw err
                res(result)
            })
        }),
        posts: await new Promise((res, rej) => {
            connection.query('SELECT * FROM posts', (err, result) => {
                if (err) throw err
                res(result)
            })
        })
    }
})()

console.log(getdata);


Answer:

Promise { <pending> }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2020-11-30
@exdude

why is IIFE here? and yes, async functions return a promise. necessaryconst getdata = await (async function() {...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question