Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to use pre-shaped result rows; fixes #3042 #3043

Merged
merged 6 commits into from
Aug 15, 2023
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/pg/lib/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Result {
if (this.rowAsArray) {
this.parseRow = this._parseRowAsArray
}
this._prebuiltEmptyResultObject = null
}

// adds a command complete message
Expand Down Expand Up @@ -60,14 +61,12 @@ class Result {
}

parseRow(rowData) {
charmander marked this conversation as resolved.
Show resolved Hide resolved
var row = {}
var row = { ... this._prebuiltEmptyResultObject }
for (var i = 0, len = rowData.length; i < len; i++) {
var rawValue = rowData[i]
var field = this.fields[i].name
if (rawValue !== null) {
row[field] = this._parsers[i](rawValue)
} else {
row[field] = null
}
}
return row
Expand All @@ -94,6 +93,14 @@ class Result {
this._parsers[i] = types.getTypeParser(desc.dataTypeID, desc.format || 'text')
}
}
this._createPrebuiltEmptyResultObject()
}
_createPrebuiltEmptyResultObject() {
var row = {};
for (var i = 0; i < this.fields.length; i++) {
row[this.fields[i].name] = null
}
this._prebuiltEmptyResultObject = row
}
}

Expand Down