I am using the co library with node-mysql2.
const newActivityCount = co.wrap(function *(memberId) {
var sql = "SELECT 1";
var conn = yield pool.getConnection();
var results = yield conn.execute(sql);
yield conn.release();
return results[0][0].newActivity;
});
This is used as
newActivityCount()
.then(..something)
.catch(err => { throw err;});
The following error is throw :
You may only yield a function, promise, generator, array, or object, but the following object was passed: "undefined"
This is how pool is defined:
// my-connection.js
var mysql = require('mysql/promise');
var bluebird = require('bluebird);
const pool = mysql.createPool({
connectionLimit: CONFIG.mysql.connectionLimit,
host : CONFIG.mysql.host,
user : CONFIG.mysql.user,
password : CONFIG.mysql.password,
database : CONFIG.mysql.database,
Promise : bluebird
});
module.exports = pool;
HOWEVER, if I change line 5 above from
yield conn.release() to conn.release()
i.e if I remove the 'yield' keyword, things work fine.
As per the author :
He does recommend using yield conn.end()
,
I am worried that if I don't 'yield' there it, I may be messing something up.
Any clues what I am missing here ?