mysql2 3.17.5 → 3.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -926,6 +926,12 @@ class BaseConnection extends EventEmitter {
926
926
  return this.addCommand(new Commands.ServerHandshake(args));
927
927
  }
928
928
 
929
+ [Symbol.dispose]() {
930
+ if (!this._closing) {
931
+ this.end();
932
+ }
933
+ }
934
+
929
935
  // ===============================================================
930
936
  end(callback) {
931
937
  if (this.config.isServer) {
package/lib/base/pool.js CHANGED
@@ -108,6 +108,12 @@ class BasePool extends EventEmitter {
108
108
  }
109
109
  }
110
110
 
111
+ [Symbol.dispose]() {
112
+ if (!this._closed) {
113
+ this.end();
114
+ }
115
+ }
116
+
111
117
  end(cb) {
112
118
  this._closed = true;
113
119
  clearTimeout(this._removeIdleTimeoutConnectionsTimer);
@@ -29,6 +29,10 @@ class BasePoolConnection extends BaseConnection {
29
29
  this._pool.releaseConnection(this);
30
30
  }
31
31
 
32
+ [Symbol.dispose]() {
33
+ this.release();
34
+ }
35
+
32
36
  end(callback) {
33
37
  if (this.config.gracefulEnd) {
34
38
  this._removeFromPool();
@@ -229,6 +229,12 @@ class PoolCluster extends EventEmitter {
229
229
  namespace.getConnection(cb);
230
230
  }
231
231
 
232
+ [Symbol.dispose]() {
233
+ if (!this._closed) {
234
+ this.end();
235
+ }
236
+ }
237
+
232
238
  end(callback) {
233
239
  const cb =
234
240
  callback !== undefined
@@ -66,6 +66,12 @@ class PromiseConnection extends EventEmitter {
66
66
  });
67
67
  }
68
68
 
69
+ async [Symbol.asyncDispose]() {
70
+ if (!this.connection._closing) {
71
+ await this.end();
72
+ }
73
+ }
74
+
69
75
  beginTransaction() {
70
76
  const c = this.connection;
71
77
  const localErr = new Error();
@@ -85,6 +85,12 @@ class PromisePool extends EventEmitter {
85
85
  });
86
86
  });
87
87
  }
88
+
89
+ async [Symbol.asyncDispose]() {
90
+ if (!this.pool._closed) {
91
+ await this.end();
92
+ }
93
+ }
88
94
  }
89
95
 
90
96
  (function (functionsToWrap) {
@@ -14,6 +14,10 @@ class PromisePoolConnection extends PromiseConnection {
14
14
  arguments
15
15
  );
16
16
  }
17
+
18
+ async [Symbol.asyncDispose]() {
19
+ this.release();
20
+ }
17
21
  }
18
22
 
19
23
  module.exports = PromisePoolConnection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mysql2",
3
- "version": "3.17.5",
3
+ "version": "3.18.0",
4
4
  "description": "fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS",
5
5
  "main": "index.js",
6
6
  "typings": "typings/mysql/index",
package/promise.d.ts CHANGED
@@ -65,6 +65,8 @@ export interface Connection extends QueryableAndExecutableBase {
65
65
 
66
66
  end(options?: any): Promise<void>;
67
67
 
68
+ [Symbol.asyncDispose](): Promise<void>;
69
+
68
70
  destroy(): void;
69
71
 
70
72
  pause(): void;
@@ -82,6 +84,7 @@ export interface Connection extends QueryableAndExecutableBase {
82
84
  export interface PoolConnection extends Connection {
83
85
  release(): void;
84
86
  connection: Connection;
87
+ [Symbol.asyncDispose](): Promise<void>;
85
88
  }
86
89
 
87
90
  export interface Pool extends Connection {
@@ -112,6 +115,8 @@ export interface PoolCluster extends EventEmitter {
112
115
 
113
116
  end(): Promise<void>;
114
117
 
118
+ [Symbol.asyncDispose](): Promise<void>;
119
+
115
120
  getConnection(): Promise<PoolConnection>;
116
121
  getConnection(group: string): Promise<PoolConnection>;
117
122
  getConnection(group: string, selector: string): Promise<PoolConnection>;
package/promise.js CHANGED
@@ -134,6 +134,12 @@ class PromisePoolCluster extends EventEmitter {
134
134
  });
135
135
  });
136
136
  }
137
+
138
+ async [Symbol.asyncDispose]() {
139
+ if (!this.poolCluster._closed) {
140
+ await this.end();
141
+ }
142
+ }
137
143
  }
138
144
 
139
145
  /**
@@ -393,6 +393,8 @@ declare class Connection extends QueryableBase(ExecutableBase(EventEmitter)) {
393
393
  end(callback?: (err: QueryError | null) => void): void;
394
394
  end(options: any, callback?: (err: QueryError | null) => void): void;
395
395
 
396
+ [Symbol.dispose](): void;
397
+
396
398
  destroy(): void;
397
399
 
398
400
  pause(): void;
@@ -53,6 +53,8 @@ declare class Pool extends QueryableBase(ExecutableBase(EventEmitter)) {
53
53
  callback?: (err: NodeJS.ErrnoException | null, ...args: any[]) => any
54
54
  ): void;
55
55
 
56
+ [Symbol.dispose](): void;
57
+
56
58
  on(event: string, listener: (...args: any[]) => void): this;
57
59
  on(event: 'connection', listener: (connection: PoolConnection) => any): this;
58
60
  on(event: 'acquire', listener: (connection: PoolConnection) => any): this;
@@ -56,6 +56,8 @@ declare class PoolCluster extends EventEmitter {
56
56
 
57
57
  end(callback?: (err: NodeJS.ErrnoException | null) => void): void;
58
58
 
59
+ [Symbol.dispose](): void;
60
+
59
61
  getConnection(
60
62
  callback: (
61
63
  err: NodeJS.ErrnoException | null,
@@ -4,6 +4,7 @@ import { Pool as PromisePool } from '../../../promise.js';
4
4
  declare class PoolConnection extends Connection {
5
5
  connection: Connection;
6
6
  release(): void;
7
+ [Symbol.dispose](): void;
7
8
  promise(promiseImpl?: PromiseConstructor): PromisePool;
8
9
  }
9
10