@@ -11,6 +11,7 @@ module.exports = Connection
1111let count = 1
1212
1313function Connection ( options = { } ) {
14+ const statements = new Map ( )
1415 const {
1516 onparameter,
1617 transform,
@@ -31,7 +32,6 @@ function Connection(options = {}) {
3132 let ready = false
3233 let write = false
3334 let next = false
34- let statements = { }
3535 let connect_timer
3636 let buffers = null
3737 let remaining = 0
@@ -73,7 +73,7 @@ function Connection(options = {}) {
7373 ) ) ) . then ( x => {
7474 x === END || done
7575 ? socket . write ( frontend . Close ( ) )
76- : socket . write ( frontend . Execute ( backend . query . cursor . rows ) )
76+ : socket . write ( frontend . ExecuteCursor ( backend . query . cursor . rows ) )
7777 } ) . catch ( err => {
7878 backend . query . reject ( err )
7979 socket . write ( frontend . Close ( ) )
@@ -94,7 +94,7 @@ function Connection(options = {}) {
9494
9595 function onparse ( ) {
9696 if ( backend . query && backend . query . statement . sig )
97- statements [ backend . query . statement . sig ] = backend . query . statement
97+ statements . set ( backend . query . statement . sig , backend . query . statement )
9898 }
9999
100100 function onauth ( type , x , onerror ) {
@@ -132,7 +132,7 @@ function Connection(options = {}) {
132132
133133 function retry ( query ) {
134134 query . retried = true
135- delete statements [ query . sig ]
135+ statements . delete ( query . sig )
136136 ready = true
137137 backend . query = backend . error = null
138138 send ( query , { sig : query . sig , str : query . str , args : query . args } )
@@ -150,8 +150,8 @@ function Connection(options = {}) {
150150 typeof options . debug === 'function' && options . debug ( id , str , args )
151151 const buffer = query . simple
152152 ? simple ( str , query )
153- : sig in statements
154- ? prepared ( statements [ sig ] , args , query )
153+ : statements . has ( sig )
154+ ? prepared ( statements . get ( sig ) , args , query )
155155 : prepare ( sig , str , args , query )
156156
157157 ready
@@ -187,23 +187,31 @@ function Connection(options = {}) {
187187
188188 function prepared ( statement , args , query ) {
189189 query . statement = statement
190- return bind ( query , args )
190+ return Buffer . concat ( [
191+ frontend . Bind ( query . statement . name , args ) ,
192+ query . cursor
193+ ? frontend . Describe ( 'P' )
194+ : Buffer . alloc ( 0 ) ,
195+ query . cursor
196+ ? frontend . ExecuteCursor ( query . cursor . rows )
197+ : frontend . Execute
198+ ] )
191199 }
192200
193201 function prepare ( sig , str , args , query ) {
194202 query . statement = { name : sig ? 'p' + uid + statement_id ++ : '' , sig }
195203 return Buffer . concat ( [
196204 frontend . Parse ( query . statement . name , str , args ) ,
197- bind ( query , args )
205+ frontend . Bind ( query . statement . name , args ) ,
206+ query . cursor
207+ ? frontend . Describe ( 'P' )
208+ : frontend . Describe ( 'S' , query . statement . name ) ,
209+ query . cursor
210+ ? frontend . ExecuteCursor ( query . cursor . rows )
211+ : frontend . Execute
198212 ] )
199213 }
200214
201- function bind ( query , args ) {
202- return query . cursor
203- ? frontend . Bind ( query . statement . name , args , query . cursor . rows )
204- : frontend . Bind ( query . statement . name , args )
205- }
206-
207215 function idle ( ) {
208216 if ( idle_timeout && ! backend . query && queries . length === 0 ) {
209217 clearTimeout ( timer )
@@ -323,7 +331,7 @@ function Connection(options = {}) {
323331 }
324332
325333 function cleanup ( ) {
326- statements = { }
334+ statements . clear ( )
327335 open = ready = write = false
328336 }
329337
0 commit comments