I'm using Node Promise (native implementation) to chain MySQL queries.
I'm using node-mysql library for MySQL connections.
var mysql = require('mysql');
var db = mysql.createPool({
host: 'localhost',
user: 'root',
password: 'root',
database: 'database'
});
The function is pretty simple and returns a Promise:
function query(sql, repl) {
return new Promise(function(resolve, reject) {
db.getConnection(function(err, connection) {
if (err)
reject(err);
else {
connection.query(sql, repl, function(err, rows) {
connection.release();
if (err)
reject(err);
else
resolve(rows);
});
}
});
});
}
However, when I run it, the application never terminates.
query('SELECT * FROM `subscriptions` LIMIT 5', []).then(function(rows) {
console.log(rows);
}, function(err) {
console.log('MySQL error: ' + err);
});
There is no more code after, but node still doesn't terminate, even though the promise gets resolved.
Could it be because connection.release() is async? I tried using the pool directly and using one single connection instead of a pool.