func RowsToCSV()

in go/utils.go [93:117]


func RowsToCSV(rows *sql.Rows) string {
	if rows == nil {
		return ""
	}
	columns, _ := rows.Columns()
	var buf bytes.Buffer
	csvWriter := csv.NewWriter(&buf)
	records := make([][]string, 0)
	for rows.Next() {
		rawResult := make([][]byte, len(columns))
		row := make([]interface{}, len(columns))
		for i := range rawResult {
			row[i] = &rawResult[i] // pointers to each string in the interface slice
		}
		// We don't consider malformed rows
		_ = rows.Scan(row...)
		s := make([]string, len(columns))
		for i, cell := range rawResult {
			s[i] = string(cell)
		}
		records = append(records, s)
	}
	csvWriter.WriteAll(records)
	return buf.String()
}