@@ -120,6 +120,14 @@ class Client extends EventEmitter {
120120 return this . _activeQuery
121121 }
122122
123+ // Returns the query that should receive the current message
124+ _getMessageTarget ( ) {
125+ if ( this . _pipelineMode ) {
126+ return this . _getCurrentPipelineQuery ( )
127+ }
128+ return this . _getActiveQuery ( )
129+ }
130+
123131 get pipelineMode ( ) {
124132 return this . _pipelineMode
125133 }
@@ -464,7 +472,7 @@ class Client extends EventEmitter {
464472 }
465473
466474 _handleRowDescription ( msg ) {
467- const activeQuery = this . _pipelineMode ? this . _getCurrentPipelineQuery ( ) : this . _getActiveQuery ( )
475+ const activeQuery = this . _getMessageTarget ( )
468476 if ( activeQuery == null ) {
469477 const error = new Error ( 'Received unexpected rowDescription message from backend.' )
470478 this . _handleErrorEvent ( error )
@@ -479,7 +487,7 @@ class Client extends EventEmitter {
479487 }
480488
481489 _handleDataRow ( msg ) {
482- const activeQuery = this . _pipelineMode ? this . _getCurrentPipelineQuery ( ) : this . _getActiveQuery ( )
490+ const activeQuery = this . _getMessageTarget ( )
483491 if ( activeQuery == null ) {
484492 const error = new Error ( 'Received unexpected dataRow message from backend.' )
485493 this . _handleErrorEvent ( error )
@@ -490,7 +498,7 @@ class Client extends EventEmitter {
490498 }
491499
492500 _handlePortalSuspended ( msg ) {
493- const activeQuery = this . _getActiveQuery ( )
501+ const activeQuery = this . _getMessageTarget ( )
494502 if ( activeQuery == null ) {
495503 const error = new Error ( 'Received unexpected portalSuspended message from backend.' )
496504 this . _handleErrorEvent ( error )
@@ -501,7 +509,7 @@ class Client extends EventEmitter {
501509 }
502510
503511 _handleEmptyQuery ( msg ) {
504- const activeQuery = this . _pipelineMode ? this . _getCurrentPipelineQuery ( ) : this . _getActiveQuery ( )
512+ const activeQuery = this . _getMessageTarget ( )
505513 if ( activeQuery == null ) {
506514 const error = new Error ( 'Received unexpected emptyQuery message from backend.' )
507515 this . _handleErrorEvent ( error )
@@ -516,7 +524,7 @@ class Client extends EventEmitter {
516524 }
517525
518526 _handleCommandComplete ( msg ) {
519- const activeQuery = this . _pipelineMode ? this . _getCurrentPipelineQuery ( ) : this . _getActiveQuery ( )
527+ const activeQuery = this . _getMessageTarget ( )
520528 if ( activeQuery == null ) {
521529 const error = new Error ( 'Received unexpected commandComplete message from backend.' )
522530 this . _handleErrorEvent ( error )
@@ -531,7 +539,7 @@ class Client extends EventEmitter {
531539 }
532540
533541 _handleParseComplete ( ) {
534- const activeQuery = this . _pipelineMode ? this . _getCurrentPipelineQuery ( ) : this . _getActiveQuery ( )
542+ const activeQuery = this . _getMessageTarget ( )
535543 if ( activeQuery == null ) {
536544 const error = new Error ( 'Received unexpected parseComplete message from backend.' )
537545 this . _handleErrorEvent ( error )
@@ -777,6 +785,15 @@ class Client extends EventEmitter {
777785 if ( config === null || config === undefined ) {
778786 throw new TypeError ( 'Client was passed a null or undefined query' )
779787 } else if ( typeof config . submit === 'function' ) {
788+ // Check if this is a custom submittable (not our Query class)
789+ // Custom submittables like pg-cursor are not supported in pipeline mode
790+ if ( this . _pipelineMode && config . submit !== Query . prototype . submit ) {
791+ const error = new Error ( 'Custom submittables are not supported in pipeline mode' )
792+ process . nextTick ( ( ) => {
793+ config . handleError ( error , this . connection )
794+ } )
795+ return config
796+ }
780797 readTimeout = config . query_timeout || this . connectionParameters . query_timeout
781798 result = query = config
782799 if ( typeof values === 'function' ) {
0 commit comments