I am trying to get data from the database through an exported function. But the problem is that the function is returning empty data. The query works if executed outside the function, but when I put the query inside the function, the return is empty. I believe that the function is returning before the query gets the result from the database.
My code:
export function queryDb(query) {
return new Promise(() => {
database.select(database.raw(query).then(data => {
return data;
}).catch(err => {
console.log(err.message);
})
)
})
}