How to use the mysql.createPoolCluster function in mysql

To help you get started, we’ve selected a few mysql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github electrode-io / electrode-ota-server / electrode-ota-server-dao-mariadb / src / ElectrodeOtaDaoRdbms.ts View on Github external
return new Promise((resolve, reject) => {
            if (this.testCluster) {
                this.cluster = this.testCluster;
            } else {
                this.cluster = createPoolCluster(options.clusterConfig);
            }

            options.poolConfigs.forEach((poolConfig: IPoolConfig) => {
                this.cluster.add(poolConfig);
            });
            this.cluster.getConnection((err, connection) => {
                if (err) {
                    reject(err);
                    return;
                }

                // connected!
                resolve();
            });
        });
    }
github mozilla / fxa-auth-db-mysql / lib / db / mysql.js View on Github external
function MySql(options) {
    options.master.database = DATABASE_NAME
    options.slave.database = DATABASE_NAME
    this.options = options
    this.ipHmacKey = options.ipHmacKey

    this.patchLevel = 0
    // poolCluster will remove the pool after `removeNodeErrorCount` errors.
    // We don't ever want to remove a pool because we only have one pool
    // for writing and reading each. Connection errors are mostly out of our
    // control for automatic recovery so monitoring of 503s is critical.
    // Since `removeNodeErrorCount` is Infinity `canRetry` must be false
    // to prevent inifinite retry attempts.
    this.poolCluster = mysql.createPoolCluster(
      {
        removeNodeErrorCount: Infinity,
        canRetry: false
      }
    )

    if (options.charset && options.charset !== REQUIRED_CHARSET) {
      log.error('createPoolCluster.invalidCharset', { charset: options.charset })
      throw new Error('You cannot use any charset besides ' + REQUIRED_CHARSET)
    } else {
      options.charset = REQUIRED_CHARSET
    }

    options.master.charset = options.charset
    options.slave.charset = options.charset
github mozilla / fxa / packages / fxa-auth-db-mysql / lib / db / mysql.js View on Github external
function MySql(options) {
    options.master.database = DATABASE_NAME;
    options.slave.database = DATABASE_NAME;
    this.options = options;
    this.ipHmacKey = options.ipHmacKey;

    this.patchLevel = 0;
    // poolCluster will remove the pool after `removeNodeErrorCount` errors.
    // We don't ever want to remove a pool because we only have one pool
    // for writing and reading each. Connection errors are mostly out of our
    // control for automatic recovery so monitoring of 503s is critical.
    // Since `removeNodeErrorCount` is Infinity `canRetry` must be false
    // to prevent inifinite retry attempts.
    this.poolCluster = mysql.createPoolCluster({
      removeNodeErrorCount: Infinity,
      canRetry: false,
    });

    if (options.charset && options.charset !== REQUIRED_CHARSET) {
      log.error('createPoolCluster.invalidCharset', {
        charset: options.charset,
      });
      throw new Error('You cannot use any charset besides ' + REQUIRED_CHARSET);
    } else {
      options.charset = REQUIRED_CHARSET;
    }

    options.master.charset = options.charset;
    options.slave.charset = options.charset;
github postmanlabs / sails-mysql-transactions / lib / db.js View on Github external
createCluster: function (config) {
        var peerNames = Object.keys(config.sources || (config.sources = {})),
            poolCluster;

        // return undefined if there is no peer config
        if (peerNames.length > 0) {
            poolCluster = mysql.createPoolCluster(config);

            peerNames.forEach(function (peerName) {
                var peerConfig = config.sources[peerName];

                // do not add this peer if it has enabled: false marked in config
                if (!peerConfig || peerConfig.enabled === false) {
                    return;
                }

                // add this peer to cluster
                poolCluster.add(peerName, peerConfig);
            });
        }

        return poolCluster || db.oneDumbSource;
    },
github mozilla / fxa / packages / fxa-auth-db-mysql / lib / db / mysql.js View on Github external
function MySql(options) {
    options.master.database = DATABASE_NAME
    options.slave.database = DATABASE_NAME
    this.options = options
    this.ipHmacKey = options.ipHmacKey

    this.patchLevel = 0
    // poolCluster will remove the pool after `removeNodeErrorCount` errors.
    // We don't ever want to remove a pool because we only have one pool
    // for writing and reading each. Connection errors are mostly out of our
    // control for automatic recovery so monitoring of 503s is critical.
    // Since `removeNodeErrorCount` is Infinity `canRetry` must be false
    // to prevent inifinite retry attempts.
    this.poolCluster = mysql.createPoolCluster(
      {
        removeNodeErrorCount: Infinity,
        canRetry: false
      }
    )

    if (options.charset && options.charset !== REQUIRED_CHARSET) {
      log.error('createPoolCluster.invalidCharset', { charset: options.charset })
      throw new Error('You cannot use any charset besides ' + REQUIRED_CHARSET)
    } else {
      options.charset = REQUIRED_CHARSET
    }

    options.master.charset = options.charset
    options.slave.charset = options.charset
github autopilotpattern / workshop / sales / lib / data.js View on Github external
const loadPool = function (callback) {
  const thisCluster = MySql.createPoolCluster();
  Consulite.refreshService('mysql', (err, hosts) => {
    populatePoolCluster(thisCluster, hosts, 'REPLICA');
    Consulite.refreshService('mysql-primary', (err, primaryHosts) => {
      populatePoolCluster(thisCluster, primaryHosts, 'PRIMARY');
      poolCluster = thisCluster;
      callback();
    });
  });
};
github godmodelabs / flora-mysql / index.js View on Github external
_getConnectionPool(server, database) {
        if (this._pools[server] && this._pools[server][database]) {
            return this._pools[server][database];
        }

        this._log.trace('creating MySQL pool "%s"', database);

        const pool = mysql.createPoolCluster({ restoreNodeTimeout: 5000 });
        const serverCfg = this._config.servers[server];
        const clusterCfg = this._prepareServerCfg(serverCfg, database);

        Object.keys(clusterCfg)
            .filter(serverId => has(clusterCfg, serverId))
            .forEach(serverId => pool.add(serverId, clusterCfg[serverId]));

        if (typeof this._pools[server] !== 'object') this._pools[server] = {};
        this._pools[server][database] = pool;
        return pool;
    }