@@ -32,17 +32,14 @@ class Connection extends EventEmitter {
32
32
if ( opts . config . socketPath ) {
33
33
this . stream = Net . connect ( opts . config . socketPath ) ;
34
34
} else {
35
- this . stream = Net . connect (
36
- opts . config . port ,
37
- opts . config . host
38
- ) ;
35
+ this . stream = Net . connect ( opts . config . port , opts . config . host ) ;
39
36
40
37
// Enable keep-alive on the socket. It's disabled by default, but the
41
38
// user can enable it and supply an initial delay.
42
39
this . stream . setKeepAlive ( true , this . config . keepAliveInitialDelay ) ;
43
40
}
44
41
// if stream is a function, treat it as "stream agent / factory"
45
- } else if ( typeof opts . config . stream === 'function' ) {
42
+ } else if ( typeof opts . config . stream === 'function' ) {
46
43
this . stream = opts . config . stream ( opts ) ;
47
44
} else {
48
45
this . stream = opts . config . stream ;
@@ -223,11 +220,15 @@ class Connection extends EventEmitter {
223
220
}
224
221
225
222
write ( buffer ) {
226
- this . stream . write ( buffer , err => {
223
+ const result = this . stream . write ( buffer , err => {
227
224
if ( err ) {
228
225
this . _handleNetworkError ( err ) ;
229
226
}
230
227
} ) ;
228
+
229
+ if ( ! result ) {
230
+ this . stream . emit ( 'pause' ) ;
231
+ }
231
232
}
232
233
233
234
// http://dev.mysql.com/doc/internals/en/sequence-id.html
@@ -260,11 +261,19 @@ class Connection extends EventEmitter {
260
261
if ( this . config . debug ) {
261
262
// eslint-disable-next-line no-console
262
263
console . log (
263
- `${ this . _internalId } ${ this . connectionId } <== ${ this . _command . _commandName } #${ this . _command . stateName ( ) } (${ [ this . sequenceId , packet . _name , packet . length ( ) ] . join ( ',' ) } )`
264
+ `${ this . _internalId } ${ this . connectionId } <== ${
265
+ this . _command . _commandName
266
+ } #${ this . _command . stateName ( ) } (${ [
267
+ this . sequenceId ,
268
+ packet . _name ,
269
+ packet . length ( )
270
+ ] . join ( ',' ) } )`
264
271
) ;
265
272
// eslint-disable-next-line no-console
266
273
console . log (
267
- `${ this . _internalId } ${ this . connectionId } <== ${ packet . buffer . toString ( 'hex' ) } `
274
+ `${ this . _internalId } ${
275
+ this . connectionId
276
+ } <== ${ packet . buffer . toString ( 'hex' ) } `
268
277
) ;
269
278
}
270
279
this . _bumpSequenceId ( 1 ) ;
@@ -277,7 +286,13 @@ class Connection extends EventEmitter {
277
286
) ;
278
287
// eslint-disable-next-line no-console
279
288
console . log (
280
- `${ this . _internalId } ${ this . connectionId } <== ${ this . _command . _commandName } #${ this . _command . stateName ( ) } (${ [ this . sequenceId , packet . _name , packet . length ( ) ] . join ( ',' ) } )`
289
+ `${ this . _internalId } ${ this . connectionId } <== ${
290
+ this . _command . _commandName
291
+ } #${ this . _command . stateName ( ) } (${ [
292
+ this . sequenceId ,
293
+ packet . _name ,
294
+ packet . length ( )
295
+ ] . join ( ',' ) } )`
281
296
) ;
282
297
}
283
298
for ( offset = 4 ; offset < 4 + length ; offset += MAX_PACKET_LENGTH ) {
@@ -402,7 +417,13 @@ class Connection extends EventEmitter {
402
417
: '(no command)' ;
403
418
// eslint-disable-next-line no-console
404
419
console . log (
405
- `${ this . _internalId } ${ this . connectionId } ==> ${ commandName } #${ stateName } (${ [ packet . sequenceId , packet . type ( ) , packet . length ( ) ] . join ( ',' ) } )`
420
+ `${ this . _internalId } ${
421
+ this . connectionId
422
+ } ==> ${ commandName } #${ stateName } (${ [
423
+ packet . sequenceId ,
424
+ packet . type ( ) ,
425
+ packet . length ( )
426
+ ] . join ( ',' ) } )`
406
427
) ;
407
428
}
408
429
}
@@ -497,7 +518,10 @@ class Connection extends EventEmitter {
497
518
cmdQuery = Connection . createQuery ( sql , values , cb , this . config ) ;
498
519
}
499
520
this . _resolveNamedPlaceholders ( cmdQuery ) ;
500
- const rawSql = this . format ( cmdQuery . sql , cmdQuery . values !== undefined ? cmdQuery . values : [ ] ) ;
521
+ const rawSql = this . format (
522
+ cmdQuery . sql ,
523
+ cmdQuery . values !== undefined ? cmdQuery . values : [ ]
524
+ ) ;
501
525
cmdQuery . sql = rawSql ;
502
526
return this . addCommand ( cmdQuery ) ;
503
527
}
@@ -839,9 +863,9 @@ class Connection extends EventEmitter {
839
863
}
840
864
841
865
static statementKey ( options ) {
842
- return (
843
- ` ${ typeof options . nestTables } / ${ options . nestTables } / ${ options . rowsAsArray } ${ options . sql } `
844
- ) ;
866
+ return ` ${ typeof options . nestTables } / ${ options . nestTables } / ${
867
+ options . rowsAsArray
868
+ } ${ options . sql } ` ;
845
869
}
846
870
}
847
871
0 commit comments