Skip to content

Commit 47ecc2c

Browse files
authored
perf(pg-native): pre-shaped result rows
Porting on pg-native #3042
1 parent 3c48f22 commit 47ecc2c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/pg-native/lib/build-result.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Result {
99
this.rowCount = undefined
1010
this.fields = []
1111
this.rows = []
12+
this._prebuiltEmptyResultObject = null
1213
}
1314

1415
consumeCommand(pq) {
@@ -19,12 +20,16 @@ class Result {
1920
consumeFields(pq) {
2021
const nfields = pq.nfields()
2122
this.fields = new Array(nfields)
23+
var row = {}
2224
for (var x = 0; x < nfields; x++) {
25+
var name = pq.fname(x);
26+
row[name] = null
2327
this.fields[x] = {
24-
name: pq.fname(x),
28+
name: name,
2529
dataTypeID: pq.ftype(x),
2630
}
2731
}
32+
this._prebuiltEmptyResultObject = { ...row }
2833
}
2934

3035
consumeRows(pq) {
@@ -36,7 +41,7 @@ class Result {
3641
}
3742

3843
consumeRowAsObject(pq, rowIndex) {
39-
const row = {}
44+
const row = { ...this._prebuiltEmptyResultObject }
4045
for (var j = 0; j < this.fields.length; j++) {
4146
row[this.fields[j].name] = this.readValue(pq, rowIndex, j)
4247
}

0 commit comments

Comments
 (0)