mysql2 3.14.3 → 3.14.4-canary.9642a1e5

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.
@@ -271,30 +271,67 @@ class Query extends Command {
271
271
  }
272
272
 
273
273
  stream(options) {
274
- options = options || {};
274
+ options = options || Object.create(null);
275
275
  options.objectMode = true;
276
- const stream = new Readable(options);
277
- stream._read = () => {
278
- this._connection && this._connection.resume();
279
- };
280
- this.on('result', (row, resultSetIndex) => {
281
- if (!stream.push(row)) {
282
- this._connection.pause();
283
- }
284
- stream.emit('result', row, resultSetIndex); // replicate old emitter
285
- });
286
- this.on('error', (err) => {
287
- stream.emit('error', err); // Pass on any errors
276
+
277
+ const stream = new Readable({
278
+ ...options,
279
+ emitClose: true,
280
+ autoDestroy: true,
281
+ read: () => {
282
+ this._connection && this._connection.resume();
283
+ },
288
284
  });
289
- this.on('end', () => {
290
- stream.push(null); // pushing null, indicating EOF
285
+
286
+ // Prevent a breaking change for users that rely on `end` event
287
+ stream.once('close', () => {
288
+ if (!stream.readableEnded) {
289
+ stream.emit('end');
290
+ }
291
291
  });
292
- this.on('fields', (fields) => {
292
+
293
+ const onResult = (row, index) => {
294
+ if (stream.destroyed) return;
295
+
296
+ if (!stream.push(row)) {
297
+ this._connection && this._connection.pause();
298
+ }
299
+
300
+ stream.emit('result', row, index); // replicate old emitter
301
+ };
302
+
303
+ const onFields = (fields) => {
304
+ if (stream.destroyed) return;
305
+
293
306
  stream.emit('fields', fields); // replicate old emitter
294
- });
295
- stream.on('end', () => {
296
- stream.emit('close');
297
- });
307
+ };
308
+
309
+ const onEnd = () => {
310
+ if (stream.destroyed) return;
311
+
312
+ stream.push(null); // pushing null, indicating EOF
313
+ };
314
+
315
+ const onError = (err) => {
316
+ stream.destroy(err);
317
+ };
318
+
319
+ stream._destroy = (err, cb) => {
320
+ this._connection && this._connection.resume();
321
+
322
+ this.removeListener('result', onResult);
323
+ this.removeListener('fields', onFields);
324
+ this.removeListener('end', onEnd);
325
+ this.removeListener('error', onError);
326
+
327
+ cb(err); // Pass on any errors
328
+ };
329
+
330
+ this.on('result', onResult);
331
+ this.on('fields', onFields);
332
+ this.on('end', onEnd);
333
+ this.on('error', onError);
334
+
298
335
  return stream;
299
336
  }
300
337
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mysql2",
3
- "version": "3.14.3",
3
+ "version": "3.14.4-canary.9642a1e5",
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",
@@ -49,7 +49,7 @@
49
49
  "aws-ssl-profiles": "^1.1.1",
50
50
  "denque": "^2.1.0",
51
51
  "generate-function": "^2.3.1",
52
- "iconv-lite": "^0.6.3",
52
+ "iconv-lite": "^0.7.0",
53
53
  "long": "^5.2.1",
54
54
  "lru.min": "^1.0.0",
55
55
  "named-placeholders": "^1.1.3",