I have a database connection for the Ojai client in node-js where i have a lot of promises, that needs to be resolved in order to establish the connection
const getAllStatuses = async (connectionString, tablename) =>{
let connection;
return ConnectionManager.getConnection(connectionString)
.then(conn =>{
connection = conn;
return connection.getStore(tablename)
}).then(newStore =>{
const store = newStore;
return store.find({})
}).then(queryResult =>{
queryResult.on('data', (document =>{
return document
}))
}).finally(()=>{
connection.close()
})
}
right now i have this in a file called databaseMapper.js
I can't seem to figure out how to return a value from this promise chainging, because i get undefined
in my controller.
module.exports.getAll = async () =>{
const data = await databaseMapper.getAllStatuses(connectionString, tables.status)
console.log(data)
return data
}
I have tried to make the function async
and then await
the promise, but stil with no luck.
Can anybody help me achieve me return the correct value (i have tested with console log, that a value is actually returned)