Skip to content

Does mysql.createPoolCluster() extend the features of mysql.createPool? #2241

Open
@danySam

Description

@danySam

I have been using createPool to create a connection pool. Now I want to use createPoolClusters.

As far as I know, both of them accepts the pool config object, which would be as follows.

{
  connectionLimit : 10,
  host            : 'example.org',
  user            : 'bob',
  password        : 'secret',
  database        : 'my_db'
}

But the on('acquire'), on('connection'), on('enqueue'), on('release') events don't work anymore.

This is how my DB module looks right now.

const mysql = require('mysql')
const Log = require('../log')
const clusters = require('./clusters.json')

const poolCluster = mysql.createPoolCluster()

for(const cluster of clusters) {
    cluster.config.connectionLimit = 20
    poolCluster.add(cluster.name, cluster.config)
}

poolCluster.on('release', function (connection) {
    Log.debug(`Connection ID ${connection.threadId} released`)
})

poolCluster.on('connection', function (connection) {
    Log.debug(`Connection ID ${connection.threadId} connected`)
})

poolCluster.on('acquire', function (connection) {
    Log.debug(`Connection ID ${connection.threadId} acquired`)
})

poolCluster.on('enqueue', function () {
    Log.debug('Waiting for available connection slot')
})

poolCluster.on('error', function (err) {
    Log.error(`Database Error ${err.code}`)
})

module.exports = poolCluster

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions