convert query result to dim result

This modifies the zone list command in such a way, that a query result
could be directly returned to the response.

With a bit of work, large query results could be rendered with a
streaming json renderer to the output.
master
Gibheer 2 years ago
parent feb4569547
commit c7ead94934
  1. 13
      zone_list.go

@ -32,17 +32,18 @@ func zoneList(c *Context, req Request, res *Response) error {
return nil
}
selClause := query.FieldListToSelect(options.Attributes, zoneListMap)
rows, err := c.tx.Query(fmt.Sprintf(`select %s from zones z`, selClause))
selClause := query.FieldListToSelect("z", options.Attributes, zoneListMap)
from := "zones z"
queryStr := fmt.Sprintf(`select %s from %s`, selClause, from)
rows, err := c.tx.Query(queryStr)
if err != nil {
res.AddMessage(LevelError, "could not return result")
return fmt.Errorf("could not get zone list: %s", err)
return fmt.Errorf("could not get zone list: %s - query: %s", err, queryStr)
}
defer rows.Close()
res.Result["zones"], err = query.RowsToMap(rows)
res.Result, err = query.RowsToMap(rows)
if err != nil {
delete(res.Result, "zones")
res.Result = nil
res.AddMessage(LevelError, "could not return result")
return fmt.Errorf("could not parse zone list: %v", err)
}

Loading…
Cancel
Save