This repository has been archived on 2018-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
node-task/node_modules/mysql2/lib/pool_connection.js

55 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2014-09-24 17:56:53 -04:00
var mysql = require('../index.js');
var Connection = mysql.Connection;
2014-09-18 15:35:58 -04:00
var inherits = require('util').inherits;
module.exports = PoolConnection;
inherits(PoolConnection, Connection);
function PoolConnection(pool, options) {
Connection.call(this, options);
2014-09-24 17:56:53 -04:00
this._pool = pool;
2014-09-18 15:35:58 -04:00
// When a fatal error occurs the connection's protocol ends, which will cause
// the connection to end as well, thus we only need to watch for the end event
// and we will be notified of disconnects.
this.on('end', this._removeFromPool);
this.on('error', this._removeFromPool);
}
2014-09-24 17:56:53 -04:00
PoolConnection.prototype.release = function () {
if (!this._pool || this._pool._closed) {
2014-09-18 15:35:58 -04:00
return;
}
2014-09-24 17:56:53 -04:00
return this._pool.releaseConnection(this);
2014-09-18 15:35:58 -04:00
};
// TODO: Remove this when we are removing PoolConnection#end
PoolConnection.prototype._realEnd = Connection.prototype.end;
PoolConnection.prototype.end = function () {
console.warn( 'Calling conn.end() to release a pooled connection is '
+ 'deprecated. In next version calling conn.end() will be '
+ 'restored to default conn.end() behavior. Use '
+ 'conn.release() instead.'
);
this.release();
};
PoolConnection.prototype.destroy = function () {
this._removeFromPool(this);
return Connection.prototype.destroy.apply(this, arguments);
};
PoolConnection.prototype._removeFromPool = function(connection) {
if (!this._pool || this._pool._closed) {
return;
}
var pool = this._pool;
this._pool = null;
pool._removeConnection(this);
};