How to distribute a shared MySQL pool across node modules?
I have a task where I will need to make multiple queries (> 10) based on the results of previous tasks. I created a connection pool using the node-mysql module.
var pool = mysql.createPool({
connectionLimit: 10,
host : config.mysql.host,
user : config.mysql.user,
password : config.mysql.password,
database : config.mysql.database
});
pool.getConnection(function(err, connection) {
//execute task1 -> task2 -> task3,4,5 and so on
})
This pool is now created in the base module. The base module additionally uses 5-6 other modules to process subtasks. Each of these modules must make queries to the database. I was wondering if I should pass this pool variable to every module and get the connection from the pool for every request. Or should I get the connection from the pool in the base unit and pass the same connection. Or if there is a better way to share a common mysql connection pool between modules in nodejs?
+3
source to share
No one has answered this question yet