description and source-codefunction Client(config) {
if (!(this instanceof Client))
return new Client(config);
EventEmitter.call(this);
this._handle = null;
if (typeof config === 'object' && config !== null)
this._config = config;
else
this._config = {};
var queryCache;
var ncache = 30;
if (typeof this._config.queryCache === 'number')
ncache = this._config.queryCache;
else if (typeof this._config.queryCache === 'object')
queryCache = this._config.queryCache; // Assume lru-cache instance
if (this._config.queryCache !== false && !queryCache)
queryCache = new LRU({ max: ncache, dispose: EMPTY_LRU_FN });
this._req = undefined;
this._queue = [];
this._queryCache = queryCache;
this._handleClosing = false;
this._tmrInactive = undefined;
this._tmrPingWaitRes = undefined;
this.connecting = false;
this.connected = false;
this.closing = false;
this.threadId = undefined;
if (this._config.threadId === false)
return;
// XXX: hack to get thread ID first before any other queries
var self = this;
this._firstQuery = {
str: 'SELECT CONNECTION_ID()',
cb: function(err, rows) {
if (err) {
self.emit('error', err);
self.close(true);
return;
}
self.threadId = rows[0][0];
self.connecting = false;
self.connected = true;
self.emit('ready');
},
result: undefined,
results: undefined,
needMetadata: false,
needColumns: false
};
}