8
8
*/
9
9
10
10
var types = require ( 'pg-types' )
11
- var escape = require ( 'js-string-escape' )
12
11
13
12
// result object returned from query
14
13
// in the 'end' event and also
@@ -65,29 +64,24 @@ Result.prototype._parseRowAsArray = function (rowData) {
65
64
return row
66
65
}
67
66
68
- // rowData is an array of text or binary values
69
- // this turns the row into a JavaScript object
70
67
Result . prototype . parseRow = function ( rowData ) {
71
- return new this . RowCtor ( this . _parsers , rowData )
68
+ var row = { }
69
+ for ( var i = 0 , len = rowData . length ; i < len ; i ++ ) {
70
+ var rawValue = rowData [ i ]
71
+ var field = this . fields [ i ] . name
72
+ if ( rawValue !== null ) {
73
+ row [ field ] = this . _parsers [ i ] ( rawValue )
74
+ } else {
75
+ row [ field ] = null
76
+ }
77
+ }
78
+ return row
72
79
}
73
80
74
81
Result . prototype . addRow = function ( row ) {
75
82
this . rows . push ( row )
76
83
}
77
84
78
- var inlineParser = function ( fieldName , i ) {
79
- return "\nthis['" +
80
- // fields containing single quotes will break
81
- // the evaluated javascript unless they are escaped
82
- // see https://github.com/brianc/node-postgres/issues/507
83
- // Addendum: However, we need to make sure to replace all
84
- // occurences of apostrophes, not just the first one.
85
- // See https://github.com/brianc/node-postgres/issues/934
86
- escape ( fieldName ) +
87
- "'] = " +
88
- 'rowData[' + i + '] == null ? null : parsers[' + i + '](rowData[' + i + ']);'
89
- }
90
-
91
85
Result . prototype . addFields = function ( fieldDescriptions ) {
92
86
// clears field definitions
93
87
// multiple query statements in 1 action can result in multiple sets
@@ -97,18 +91,11 @@ Result.prototype.addFields = function (fieldDescriptions) {
97
91
this . fields = [ ]
98
92
this . _parsers = [ ]
99
93
}
100
- var ctorBody = ''
101
94
for ( var i = 0 ; i < fieldDescriptions . length ; i ++ ) {
102
95
var desc = fieldDescriptions [ i ]
103
96
this . fields . push ( desc )
104
97
var parser = this . _getTypeParser ( desc . dataTypeID , desc . format || 'text' )
105
98
this . _parsers . push ( parser )
106
- // this is some craziness to compile the row result parsing
107
- // results in ~60% speedup on large query result sets
108
- ctorBody += inlineParser ( desc . name , i )
109
- }
110
- if ( ! this . rowAsArray ) {
111
- this . RowCtor = Function ( 'parsers' , 'rowData' , ctorBody )
112
99
}
113
100
}
114
101
0 commit comments