<commit_before>const mysql = require('mysql');
const config = require('../../../../config.json');

type MysqlOptions = {
  user: string;
  database: string;
  password: string;
  host: string;
  port: number;
  max: number;
  idleTimeoutMillis: number;
};

// Default configuration values, notice we dont have password.
const DEFAULTS = {
  user: 'voiceweb',
  database: 'voiceweb',
  password: <PASSWORD>,
  host: 'localhost',
  port: 3306,
  max: 10,
  idleTimeoutMillis: 30000
};

export default class Mysql {
  pool: any;

  constructor(options?: MysqlOptions) {
    options = options || Object.create(null);
    // For configuring, use the following order of priority:
    //   1. passed in options
    //   2. options in config.json
    //   3. hard coded DEFAULTS
    var myConfig = {
        user: options.user || config.MYSQLUSER || DEFAULTS.user,
        database: options.database || config.MYSQLDB || DEFAULTS.database,
        password: options.password || config.MYSQLPASS || DEFAULTS.password,
        host: options.host || config.MYSQLHOST || DEFAULTS.host,
        port: options.port || config.MYSQLPORT || DEFAULTS.port,
        max: options.max || DEFAULTS.max,
        idleTimeoutMillis: options.idleTimeoutMillis ||
            DEFAULTS.idleTimeoutMillis,
    };

    let isEmptyString = function(str: string): boolean {
      return typeof str !== 'undefined'
           && !str.length;
    };

    if (isEmptyString(options.password)
        || (!options.password && isEmptyString(config.MYSQLPASS))) {
      myConfig.password = null;
    }

    this.pool = mysql.createPool({
        connectionLimit : 100,
        host            : myConfig.host,<commit_msg>Simplify check for empty password string<commit_after>const mysql = require('mysql');
const config = require('../../../../config.json');

type MysqlOptions = {
  user: string;
  database: string;
  password: string;
  host: string;
  port: number;
  max: number;
  idleTimeoutMillis: number;
};

// Default configuration values, notice we dont have password.
const DEFAULTS = {
  user: 'voiceweb',
  database: 'voiceweb',
  password: <PASSWORD>,
  host: 'localhost',
  port: 3306,
  max: 10,
  idleTimeoutMillis: 30000
};

export default class Mysql {
  pool: any;

  constructor(options?: MysqlOptions) {
    options = options || Object.create(null);
    // For configuring, use the following order of priority:
    //   1. passed in options
    //   2. options in config.json
    //   3. hard coded DEFAULTS
    var myConfig = {
        user: options.user || config.MYSQLUSER || DEFAULTS.user,
        database: options.database || config.MYSQLDB || DEFAULTS.database,
        password: options.password || config.MYSQLPASS || DEFAULTS.password,
        host: options.host || config.MYSQLHOST || DEFAULTS.host,
        port: options.port || config.MYSQLPORT || DEFAULTS.port,
        max: options.max || DEFAULTS.max,
        idleTimeoutMillis: options.idleTimeoutMillis ||
            DEFAULTS.idleTimeoutMillis,
    };

    // Empty strings are evaluated to false, so if the password is an empty
    // string, the next one in the order of priority would be used. Prevent
    // this.
    if (options.password === ''
        || (!options.password && config.MYSQLPASS === '')) {
      // An empty password is equivalent to no password.
      myConfig.password = <PASSWORD>;
    }

    this.pool = mysql.createPool({
        connectionLimit : 100,
        host            : myConfig.host,
{'fraction_non_alphanumeric': 0.12410020155485171, 'fraction_numerical': 0.009789807083213361, 'mean_word_length': 2.7435344827586206, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6407642', 'n_tokens_mistral': 1022, 'n_tokens_neox': 1028, 'n_words': 283}