My changes are all in this function:
fetchRows(sqlQuery) {
let aPromise = new Promise((resolve, reject) => {
setTimeout(function () {
if (sqlQuery) {
resolve(I.getResults(sqlQuery));
}
reject("Not a valid query");
}, 38);
});
return aPromise.then((sqlQuery) => {
console.log('Success:', sqlQuery);
}).catch((errorMessage) => {
console.log(errorMessage);
});
},
What property is undefined? Is something missing from the promise structure? (I am a js promise noob) If i remove everything and just wrap up the "I.getResults(sqlQuery)" it runs fine, something about the promise is throwing it off I think.
Here is the getResults function
/**
* Get query resultset
* @param {*} sqlQuery
*/
getResults(sqlQuery) {
return connection.then(client => {
return client.query({
rowMode: 'array',
text: sqlQuery,
}).then(res => {
return res.rows;
}).catch(e => {
client.release();
pool.end();
console.error('query error', e.message, e.stack);
});
});
}