@@ -74,38 +74,30 @@ export function Pool(options: mixed) {
74
74
} ;
75
75
}
76
76
77
- function getInnerMap (
78
- outerMap : Map < string , mixed > ,
79
- query : string ,
80
- values ?: Array < mixed > ,
81
- ) {
82
- if ( values == null || values . length === 0 ) {
83
- return [ outerMap , query ] ;
84
- }
85
- // If we have parameters, each becomes as a nesting layer for Maps.
86
- // We want to find (or create as needed) the innermost Map, and return that.
87
- let innerMap = outerMap ;
77
+ Pool . prototype . query = function ( query : string , values ?: Array < mixed > ) {
78
+ const pool = this . pool ;
79
+ const outerMap = unstable_getCacheForType ( this . createResultMap ) ;
80
+
81
+ let innerMap : Map < any , any > = outerMap ;
88
82
let key = query ;
89
- for ( let i = 0 ; i < values . length ; i ++ ) {
90
- let nextMap = innerMap . get ( key ) ;
91
- if ( nextMap === undefined ) {
92
- nextMap = new Map ( ) ;
93
- innerMap . set ( key , nextMap ) ;
83
+ if ( values != null ) {
84
+ // If we have parameters, each becomes as a nesting layer for Maps.
85
+ // We want to find (or create as needed) the innermost Map, and return that.
86
+ for ( let i = 0 ; i < values . length ; i ++ ) {
87
+ let nextMap = innerMap . get ( key ) ;
88
+ if ( nextMap === undefined ) {
89
+ nextMap = new Map ( ) ;
90
+ innerMap . set ( key , nextMap ) ;
91
+ }
92
+ innerMap = nextMap ;
93
+ // Postgres bindings convert everything to strings:
94
+ // https://node-postgres.com/features/queries#parameterized-query
95
+ // We reuse their algorithm instead of reimplementing.
96
+ key = prepareValue ( values [ i ] ) ;
94
97
}
95
- innerMap = nextMap ;
96
- // Postgres bindings convert everything to strings:
97
- // https://node-postgres.com/features/queries#parameterized-query
98
- // We reuse their algorithm instead of reimplementing.
99
- key = prepareValue ( values [ i ] ) ;
100
98
}
101
- return [ innerMap , key ] ;
102
- }
103
99
104
- Pool . prototype . query = function ( query : string , values ?: Array < mixed > ) {
105
- const pool = this . pool ;
106
- const outerMap = unstable_getCacheForType ( this . createResultMap ) ;
107
- const [ innerMap , key ] = getInnerMap ( outerMap , query , values ) ;
108
- let entry = innerMap . get ( key ) ;
100
+ let entry : Result | void = innerMap . get ( key ) ;
109
101
if ( ! entry ) {
110
102
const thenable = pool . query ( query , values ) ;
111
103
entry = toResult ( thenable ) ;
0 commit comments