Skip to content

Commit

Permalink
Support decoding multiple series (closes #7)
Browse files Browse the repository at this point in the history
  • Loading branch information
bminer committed Jan 23, 2019
1 parent 1626d77 commit 0fb5693
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
3 changes: 1 addition & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ func (c *helperClient) DecodeQuery(q string, result interface{}) (err error) {
return
}

series := results[0].Series[0]
err = decode(series, result)
err = decode(results[0].Series, result)

return
}
Expand Down
29 changes: 15 additions & 14 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ import (
"github.com/mitchellh/mapstructure"
)



// Decode is used to process data returned by an InfluxDb query and uses reflection
// to transform it into an array of structs of type result.
//
// This function is used internally by the Query function.
func decode(influxResult influxModels.Row, result interface{}) error {
func decode(influxResult []influxModels.Row, result interface{}) error {
influxData := make([]map[string]interface{}, 0)

for _, v := range influxResult.Values {
r := make(map[string]interface{})
for i, c := range influxResult.Columns {
if len(v) >= i+1 {
r[c] = v[i]
for _, series := range influxResult {
for _, v := range series.Values {
r := make(map[string]interface{})
for i, c := range series.Columns {
if len(v) >= i+1 {
r[c] = v[i]
}
}
}
for tag, val := range influxResult.Tags {
r[tag] = val
}
r["InfluxMeasurement"] = influxResult.Name
for tag, val := range series.Tags {
r[tag] = val
}
r["InfluxMeasurement"] = series.Name

influxData = append(influxData, r)
influxData = append(influxData, r)
}
}

config := &mapstructure.DecoderConfig{
Expand All @@ -54,3 +54,4 @@ func decode(influxResult influxModels.Row, result interface{}) error {

return decoder.Decode(influxData)
}

0 comments on commit 0fb5693

Please sign in to comment.