Skip to content

Instantly share code, notes, and snippets.

@locona
Created November 7, 2017 05:03
Show Gist options
  • Save locona/18ba42b0b8cfd0feccd2e25928d22022 to your computer and use it in GitHub Desktop.
Save locona/18ba42b0b8cfd0feccd2e25928d22022 to your computer and use it in GitHub Desktop.
func convertToResult(rows *sql.Rows) (res [][]interface{}, err error) {
columns, err := rows.Columns()
if err != nil {
return nil, err
}
values := make([]sql.RawBytes, len(columns))
args := make([]interface{}, len(values))
for i := range values {
args[i] = &values[i]
}
for rows.Next() {
if err := rows.Scan(args...); err != nil {
return nil, err
}
row := []interface{}{}
for _, col := range values {
row = append(row, string(col))
}
res = append(res, row)
}
return res, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment