示例#1
0
func arrangeResult(rows *core.Rows, name string) (interface{}, error) {
	columnNames, err := rows.Columns()

	series := seriesStruct{}
	series.Columns = columnNames
	series.Name = name

	for rows.Next() {
		columnValues := make([]interface{}, len(columnNames))

		err = rows.ScanSlice(&columnValues)
		if err != nil {
			return nil, err
		}

		// bytes -> string
		for i := range columnValues {
			switch columnValues[i].(type) {
			case []byte:
				columnValues[i] = fmt.Sprintf("%s", columnValues[i])
			}
		}

		series.Values = append(series.Values, columnValues)
	}

	return series, err
}
示例#2
0
func rows2maps(rows *core.Rows) (resultsSlice []map[string][]byte, err error) {
	fields, err := rows.Columns()
	if err != nil {
		return nil, err
	}
	for rows.Next() {
		result, err := row2map(rows, fields)
		if err != nil {
			return nil, err
		}
		resultsSlice = append(resultsSlice, result)
	}

	return resultsSlice, nil
}