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:
francesco 2025-02-11 17:12:10 +01:00 committed by GitHub
parent 0792f0904a
commit f1586932fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)
}