mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
perf(pg-native): pre-shaped result rows (#3369)
* perf(pg-native): pre-shaped result rows Porting on pg-native https://github.com/brianc/node-postgres/issues/3042 * fix: lint * perf(pg-native): avoid useless spread
This commit is contained in:
parent
0792f0904a
commit
f1586932fd
@ -9,6 +9,7 @@ class Result {
|
||||
this.rowCount = undefined
|
||||
this.fields = []
|
||||
this.rows = []
|
||||
this._prebuiltEmptyResultObject = null
|
||||
}
|
||||
|
||||
consumeCommand(pq) {
|
||||
@ -19,9 +20,12 @@ class Result {
|
||||
consumeFields(pq) {
|
||||
const nfields = pq.nfields()
|
||||
this.fields = new Array(nfields)
|
||||
this._prebuiltEmptyResultObject = {}
|
||||
for (var x = 0; x < nfields; x++) {
|
||||
var name = pq.fname(x)
|
||||
this._prebuiltEmptyResultObject[name] = null
|
||||
this.fields[x] = {
|
||||
name: pq.fname(x),
|
||||
name: name,
|
||||
dataTypeID: pq.ftype(x),
|
||||
}
|
||||
}
|
||||
@ -36,7 +40,7 @@ class Result {
|
||||
}
|
||||
|
||||
consumeRowAsObject(pq, rowIndex) {
|
||||
const row = {}
|
||||
const row = { ...this._prebuiltEmptyResultObject }
|
||||
for (var j = 0; j < this.fields.length; j++) {
|
||||
row[this.fields[j].name] = this.readValue(pq, rowIndex, j)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user