diff options
author | Joel Kronqvist <joel.h.kronqvist@gmail.com> | 2022-03-05 19:02:27 +0200 |
---|---|---|
committer | Joel Kronqvist <joel.h.kronqvist@gmail.com> | 2022-03-05 19:02:27 +0200 |
commit | 5d309ff52cd399a6b71968a6b9a70c8ac0b98981 (patch) | |
tree | 360f7eb50f956e2367ef38fa1fc6ac7ac5258042 /node_modules/mysql2/lib/pool_connection.js | |
parent | b500a50f1b97d93c98b36ed9a980f8188d648147 (diff) | |
download | LYLLRuoka-5d309ff52cd399a6b71968a6b9a70c8ac0b98981.tar.gz LYLLRuoka-5d309ff52cd399a6b71968a6b9a70c8ac0b98981.zip |
Added node_modules for the updating to work properly.
Diffstat (limited to 'node_modules/mysql2/lib/pool_connection.js')
-rw-r--r-- | node_modules/mysql2/lib/pool_connection.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/node_modules/mysql2/lib/pool_connection.js b/node_modules/mysql2/lib/pool_connection.js new file mode 100644 index 0000000..be49a73 --- /dev/null +++ b/node_modules/mysql2/lib/pool_connection.js @@ -0,0 +1,65 @@ +'use strict'; + +const Connection = require('../index.js').Connection; + +class PoolConnection extends Connection { + constructor(pool, options) { + super(options); + this._pool = pool; + // 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. + // REVIEW: Moved to `once` + this.once('end', () => { + this._removeFromPool(); + }); + this.once('error', () => { + this._removeFromPool(); + }); + } + + release() { + if (!this._pool || this._pool._closed) { + return; + } + this._pool.releaseConnection(this); + } + + promise(promiseImpl) { + const PromisePoolConnection = require('../promise').PromisePoolConnection; + return new PromisePoolConnection(this, promiseImpl); + } + + end() { + const err = new Error( + '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.emit('warn', err); + // eslint-disable-next-line no-console + console.warn(err.message); + this.release(); + } + + destroy() { + this._removeFromPool(); + super.destroy(); + } + + _removeFromPool() { + if (!this._pool || this._pool._closed) { + return; + } + const pool = this._pool; + this._pool = null; + pool._removeConnection(this); + } +} + +PoolConnection.statementKey = Connection.statementKey; +module.exports = PoolConnection; + +// TODO: Remove this when we are removing PoolConnection#end +PoolConnection.prototype._realEnd = Connection.prototype.end; |