I'm wondering if this approach is correct or does it need further refinements, maybe promisify custom mySQL getConnection
method as well???
request: function(queryRequest) {
return new Promise(function(resolve, reject){
Database.getConnection(function(error, connection){
if(error) {
reject({error: error, queryRequest: queryRequest});
} else {
connection.query(queryRequest.sql, queryRequest.values, function(error, rows, fields){
if(error) {
reject({error: error, queryRequest: queryRequest});
} else {
resolve({rows: rows, fields: fields, queryRequest: queryRequest});
}
});
}
});
});
},
The getConnection
method defined in Database
module.
getConnection: function(callback) {
this.pool.getConnection(function(error, connection){
callback(error, connection);
});
},