@@ -11,6 +11,7 @@ module.exports = Connection
11
11
let count = 1
12
12
13
13
function Connection ( options = { } ) {
14
+ const statements = new Map ( )
14
15
const {
15
16
onparameter,
16
17
transform,
@@ -31,7 +32,6 @@ function Connection(options = {}) {
31
32
let ready = false
32
33
let write = false
33
34
let next = false
34
- let statements = { }
35
35
let connect_timer
36
36
let buffers = null
37
37
let remaining = 0
@@ -73,7 +73,7 @@ function Connection(options = {}) {
73
73
) ) ) . then ( x => {
74
74
x === END || done
75
75
? socket . write ( frontend . Close ( ) )
76
- : socket . write ( frontend . Execute ( backend . query . cursor . rows ) )
76
+ : socket . write ( frontend . ExecuteCursor ( backend . query . cursor . rows ) )
77
77
} ) . catch ( err => {
78
78
backend . query . reject ( err )
79
79
socket . write ( frontend . Close ( ) )
@@ -94,7 +94,7 @@ function Connection(options = {}) {
94
94
95
95
function onparse ( ) {
96
96
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 )
98
98
}
99
99
100
100
function onauth ( type , x , onerror ) {
@@ -132,7 +132,7 @@ function Connection(options = {}) {
132
132
133
133
function retry ( query ) {
134
134
query . retried = true
135
- delete statements [ query . sig ]
135
+ statements . delete ( query . sig )
136
136
ready = true
137
137
backend . query = backend . error = null
138
138
send ( query , { sig : query . sig , str : query . str , args : query . args } )
@@ -150,8 +150,8 @@ function Connection(options = {}) {
150
150
typeof options . debug === 'function' && options . debug ( id , str , args )
151
151
const buffer = query . simple
152
152
? simple ( str , query )
153
- : sig in statements
154
- ? prepared ( statements [ sig ] , args , query )
153
+ : statements . has ( sig )
154
+ ? prepared ( statements . get ( sig ) , args , query )
155
155
: prepare ( sig , str , args , query )
156
156
157
157
ready
@@ -187,23 +187,31 @@ function Connection(options = {}) {
187
187
188
188
function prepared ( statement , args , query ) {
189
189
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
+ ] )
191
199
}
192
200
193
201
function prepare ( sig , str , args , query ) {
194
202
query . statement = { name : sig ? 'p' + uid + statement_id ++ : '' , sig }
195
203
return Buffer . concat ( [
196
204
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
198
212
] )
199
213
}
200
214
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
-
207
215
function idle ( ) {
208
216
if ( idle_timeout && ! backend . query && queries . length === 0 ) {
209
217
clearTimeout ( timer )
@@ -323,7 +331,7 @@ function Connection(options = {}) {
323
331
}
324
332
325
333
function cleanup ( ) {
326
- statements = { }
334
+ statements . clear ( )
327
335
open = ready = write = false
328
336
}
329
337
0 commit comments