node_modules/mariadb/lib/cmd/batch-rewrite.js
/**
   * Define params events.
   * Each parameter indicate that he is written to socket,
   * emitting event so next parameter can be written.
   */
Define params events.
Each parameter indicate that he is written to socket,
emitting event so next parameter can be written.
Define params events . Each parameter indicate that he is written to socket emitting event so next parameter can be written .
registerStreamSendEvent(packet, info) {
    this.paramWritten = function () {
      let flushed = false;
      while (!flushed) {
        if (this.packet.haveErrorResponse) {
          this.sending = false;
          this.emit('send_end');
          return;
        }
        if (this.currentParam === this.valueRow.length) {
          flushed =
            packet.writeString(this.parseResults.partList[this.parseResults.partList.length - 2]) ||
            flushed;
          flushed =
            packet.mark(!this.parseResults.reWritable || this.valueIdx === this.values.length) ||
            flushed;
          if (this.valueIdx < this.values.length) {
            this.valueRow = this.values[this.valueIdx++];
            this.currentParam = 0;
          } else {
            this.sending = false;
            this.emit('send_end');
            return;
          }
        }
        flushed = packet.writeString(this.parseResults.partList[this.currentParam + 1]) || flushed;
        const value = this.valueRow[this.currentParam];
        if (value === null) {
          flushed = packet.writeStringAscii('NULL') || flushed;
          this.currentParam++;
          continue;
        }
        if (
          typeof value === 'object' &&
          typeof value.pipe === 'function' &&
          typeof value.read === 'function'
        ) {
          flushed = packet.writeInt8(QUOTE) || flushed;
          value.once(
            'end',
            function () {
              packet.writeInt8(QUOTE);
              this.currentParam++;
              this.paramWritten();
            }.bind(this)
          );
          value.on('data', function (chunk) {
            packet.writeBufferEscape(chunk);
          });
          return;
        }
        flushed = this.writeParam(packet, value, this.opts, info) || flushed;
        this.currentParam++;
      }
      if (this.sending) setImmediate(this.paramWritten.bind(this));
    }.bind(this);
  }
registerStreamSendEvent ( packet , info ) { this . paramWritten = function ( ) { let flushed = false ; while ( ! flushed ) { if ( this . packet . haveErrorResponse ) { this . sending = false ; this . emit ( 'send_end' ) ; return ; } if ( this . currentParam === this . valueRow . length ) { flushed = packet . writeString ( this . parseResults . partList [ this . parseResults . partList . length - 2 ] ) || flushed ; flushed = packet . mark ( ! this . parseResults . reWritable || this . valueIdx === this . values . length ) || flushed ; if ( this . valueIdx < this . values . length ) { this . valueRow = this . values [ this . valueIdx ++ ] ; this . currentParam = 0 ; } else { this . sending = false ; this . emit ( 'send_end' ) ; return ; } } flushed = packet . writeString ( this . parseResults . partList [ this . currentParam + 1 ] ) || flushed ; const value = this . valueRow [ this . currentParam ] ; if ( value === null ) { flushed = packet . writeStringAscii ( 'NULL' ) || flushed ; this . currentParam ++ ; continue ; } if ( typeof value === 'object' && typeof value . pipe === 'function' && typeof value . read === 'function' ) { flushed = packet . writeInt8 ( QUOTE ) || flushed ; value . once ( 'end' , function ( ) { packet . writeInt8 ( QUOTE ) ; this . currentParam ++ ; this . paramWritten ( ) ; } . bind ( this ) ) ; value . on ( 'data' , function ( chunk ) { packet . writeBufferEscape ( chunk ) ; } ) ; return ; } flushed = this . writeParam ( packet , value , this . opts , info ) || flushed ; this . currentParam ++ ; } if ( this . sending ) setImmediate ( this . paramWritten . bind ( this ) ) ; } . bind ( this ) ; }
Define params events.
Define params events .
// all parameters from row are written. // still remaining rows // all rows are written //******************************************** // param is stream, //******************************************** //******************************************** // param isn't stream. directly write in buffer //********************************************