@@ -39,28 +39,34 @@ class Result {
3939 consumeRows ( pq ) {
4040 const tupleCount = pq . ntuples ( )
4141 this . rows = new Array ( tupleCount )
42+ // all the values in one native call when libpq has it, instead of one or two calls per value
43+ const values = typeof pq . getvalues === 'function' ? pq . getvalues ( ) : undefined
4244 for ( let i = 0 ; i < tupleCount ; i ++ ) {
43- this . rows [ i ] = this . _arrayMode ? this . consumeRowAsArray ( pq , i ) : this . consumeRowAsObject ( pq , i )
45+ this . rows [ i ] = this . _arrayMode ? this . consumeRowAsArray ( pq , i , values ) : this . consumeRowAsObject ( pq , i , values )
4446 }
4547 }
4648
47- consumeRowAsObject ( pq , rowIndex ) {
49+ consumeRowAsObject ( pq , rowIndex , values ) {
4850 const row = { ...this . _prebuiltEmptyResultObject }
4951 for ( let j = 0 ; j < this . fields . length ; j ++ ) {
50- row [ this . fields [ j ] . name ] = this . readValue ( pq , rowIndex , j )
52+ row [ this . fields [ j ] . name ] = this . readValue ( pq , rowIndex , j , values )
5153 }
5254 return row
5355 }
5456
55- consumeRowAsArray ( pq , rowIndex ) {
57+ consumeRowAsArray ( pq , rowIndex , values ) {
5658 const row = new Array ( this . fields . length )
5759 for ( let j = 0 ; j < this . fields . length ; j ++ ) {
58- row [ j ] = this . readValue ( pq , rowIndex , j )
60+ row [ j ] = this . readValue ( pq , rowIndex , j , values )
5961 }
6062 return row
6163 }
6264
63- readValue ( pq , rowIndex , colIndex ) {
65+ readValue ( pq , rowIndex , colIndex , values ) {
66+ if ( values !== undefined ) {
67+ const value = values [ rowIndex * this . fields . length + colIndex ]
68+ return value === null ? null : this . _parsers [ colIndex ] ( value )
69+ }
6470 const rawValue = pq . getvalue ( rowIndex , colIndex )
6571 if ( rawValue === '' && pq . getisnull ( rowIndex , colIndex ) ) {
6672 return null
0 commit comments