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
node.js mysql connection-pooling node-mysql


source to share


No one has answered this question yet

See similar questions:

21
How to properly pass mysql connection with routes using express.js

or similar:

1762
How to import SQL file using command line in MySQL?
1290
How do I get a list of user accounts using the command line in MySQL?
1105
How to reset AUTO_INCREMENT in MySQL?
1086
How to connect to MySQL database in Python?
867
How to remove npm modules in js node?
57
node.js + mysql connection pool
fourteen
node-mysql joining pools
3
How to get the number of unused / used connections in nodejs mysql connection pool?
0
chose connection pool based on mysql restful parameter node
0
Nodejs Module for mysql - Pooled connections not showing in status



All Articles
Loading...
X
Show
Funny
Dev
Pics