mirror of https://github.com/jackc/pgx.git
Merge pull request #784 from zikaeroh/fix-column-perf
Cache column names in stdlib Rowspull/816/head
commit
eeda0368e6
|
@ -412,15 +412,20 @@ type Rows struct {
|
|||
valueFuncs []rowValueFunc
|
||||
skipNext bool
|
||||
skipNextMore bool
|
||||
|
||||
columnNames []string
|
||||
}
|
||||
|
||||
func (r *Rows) Columns() []string {
|
||||
fieldDescriptions := r.rows.FieldDescriptions()
|
||||
names := make([]string, 0, len(fieldDescriptions))
|
||||
for _, fd := range fieldDescriptions {
|
||||
names = append(names, string(fd.Name))
|
||||
if r.columnNames == nil {
|
||||
fields := r.rows.FieldDescriptions()
|
||||
r.columnNames = make([]string, len(fields))
|
||||
for i, fd := range fields {
|
||||
r.columnNames[i] = string(fd.Name)
|
||||
}
|
||||
}
|
||||
return names
|
||||
|
||||
return r.columnNames
|
||||
}
|
||||
|
||||
// ColumnTypeDatabaseTypeName returns the database system type name. If the name is unknown the OID is returned.
|
||||
|
|
Loading…
Reference in New Issue