Cache column names in stdlib Rows

pull/784/head
zikaeroh 2020-06-28 16:18:13 -07:00
parent 3568b908c0
commit 84510c4590
1 changed files with 10 additions and 5 deletions

View File

@ -412,15 +412,20 @@ type Rows struct {
valueFuncs []rowValueFunc valueFuncs []rowValueFunc
skipNext bool skipNext bool
skipNextMore bool skipNextMore bool
columnNames []string
} }
func (r *Rows) Columns() []string { func (r *Rows) Columns() []string {
fieldDescriptions := r.rows.FieldDescriptions() if r.columnNames == nil {
names := make([]string, 0, len(fieldDescriptions)) fields := r.rows.FieldDescriptions()
for _, fd := range fieldDescriptions { r.columnNames = make([]string, len(fields))
names = append(names, string(fd.Name)) 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. // ColumnTypeDatabaseTypeName returns the database system type name. If the name is unknown the OID is returned.