I am facing an issue with returning the result
parameter from the getColumn
function. Despite my attempts, it keeps logging as undefined.
The connection function establishes a connection to a SQL database and retrieves a data set through a query.
Is there a way for me to effectively pass the variable up the promise chain?
getColumn = function(columnName, table) {
sql.connect(config.properties)
.then(result => {
let request = new sql.Request();
request.query("SELECT " + columnName + " FROM " + table)
.then(result => {
// trying to return this 'result' from the getColumn function
return result
}).catch(err => {
// Error handling for queries
})
}).catch(err => {
// Error handling for connections
})
} //
console.log(getColumn('username', 'Login'))