From c7ead94934a63649af344ce9a3fc680545c2de09 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Mon, 3 May 2021 19:39:41 +0200 Subject: [PATCH] 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. --- zone_list.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/zone_list.go b/zone_list.go index 19112a6..63bb27e 100644 --- a/zone_list.go +++ b/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) }