UNPKG

dl

Version:

DreamLab Libs

26 lines (22 loc) 815 B
var MySQLCredentialPool = require('./MySQLCredentialPool.js').MySQLCredentialPool, instances = {}, MySQLCredentialPoolFactory = {}; MySQLCredentialPoolFactory.data = {}; MySQLCredentialPoolFactory.getInstance = function (name) { if (instances[name]) { return instances[name]; } else if (this.data[name]) { instances[name] = new MySQLCredentialPool(this.data[name].credential, this.data[name].identity); instances[name].connect(); return instances[name]; } else { throw new Error("Unknown instance"); } }; MySQLCredentialPoolFactory.addInstance = function (name, credential, identity) { this.data[name] = { "credential": credential, "identity": identity }; }; exports.MySQLCredentialPoolFactory = MySQLCredentialPoolFactory;