<commit_before>/**
 * @fileOverview Will handle connectivity to the databases and alert on issues.
 */

var EventEmitter = require('events').EventEmitter;
var util = require('util');

var Promise = require('bluebird');
var mongoose = require('mongoose');
var log = require('../util/logger').getLogger('kansas.main.ConnectionMongo');

// models
var AppModel = require('../models/application.model');
var TokenModel = require('../models/token.model');

/**
 * This module is an instance of EventEmitter.
 *
 * @event `open`: Emitted after we `connected` and `onOpen` is executed
 *   on all of this connections models.
 * @event `close`: Emitted after we `disconnected` and `onClose` executed
 *   on all of this connections models.
 * @event `error`: Emitted when an error occurs on this connection.
 *
 * @param {Object} A dict with required options (see assignment bellow).
 * @constructor
 * @extends {events.EventEmitter}
 */
var Conn = module.exports = function(opts) {
  EventEmitter.call(this);

  /** @type {boolean} Indicates if inited and event handlers added to libs */
  this._initialized = false;

  /**
   * Reference for the mongo reconnect setTimeout index or null.
   * @type {?setTimeout}
   * @private
   */
  this._mongoReconnTimer = null;

  /** @type {?mongoose.connect} The mongoose connection object */
  this.db = null;

  this.appModel = new AppModel();
  this.tokenModel = new TokenModel();

  /** @type {Object} A dict with options */
  this.opts = {
    user: opts.user,
    password: <PASSWORD>,
    hostname: opts.hostname,
    reconnectTime: opts.reconnectTime,
    database: opts.database,
  };

};
util.inherits(Conn, EventEmitter);
<commit_msg>Ensure only one instance per database name exists<commit_after>/**
 * @fileOverview Will handle connectivity to the databases and alert on issues.
 */

var EventEmitter = require('events').EventEmitter;
var util = require('util');

var Promise = require('bluebird');
var mongoose = require('mongoose');
var log = require('../util/logger').getLogger('kansas.main.ConnectionMongo');

// models
var AppModel = require('../models/application.model');
var TokenModel = require('../models/token.model');

/**
 * This module is an instance of EventEmitter.
 *
 * @event `open`: Emitted after we `connected` and `onOpen` is executed
 *   on all of this connections models.
 * @event `close`: Emitted after we `disconnected` and `onClose` executed
 *   on all of this connections models.
 * @event `error`: Emitted when an error occurs on this connection.
 *
 * @param {Object} A dict with required options (see assignment bellow).
 * @constructor
 * @extends {events.EventEmitter}
 */
var Conn = module.exports = function(opts) {
  if (opts.database in Conn.instances) {
    return Conn.instances[opts.database];
  }
  EventEmitter.call(this);

  /** @type {boolean} Indicates if inited and event handlers added to libs */
  this._initialized = false;

  /**
   * Reference for the mongo reconnect setTimeout index or null.
   * @type {?setTimeout}
   * @private
   */
  this._mongoReconnTimer = null;

  /** @type {?mongoose.connect} The mongoose connection object */
  this.db = null;

  this.appModel = new AppModel();
  this.tokenModel = new TokenModel();

  /** @type {Object} A dict with options */
  this.opts = {
    user: opts.user,
    password: <PASSWORD>,
    hostname: opts.hostname,
    reconnectTime: opts.reconnectTime,
    database: opts.database,
  };
  Conn.instances[opts.database] = this;

};
util.inherits(Conn, EventEmitter);

/** @type {Object} Will contain instances of Conn with the db name as keys */
Conn.instances = {};

{'fraction_non_alphanumeric': 0.13263332412268583, 'fraction_numerical': 0.0, 'mean_word_length': 3.859060402684564, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5604747', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1073, 'n_words': 349}