func queryDB(client influx.Client, cmd string) (res []influx.Result, err error) { q := influx.Query{ Command: cmd, Database: "", } if response, err := client.Query(q); err == nil { if response.Error() != nil { return res, response.Error() } res = response.Results } return res, nil }
func queryDB(clnt influxpackage.Client, cmd string, dbname string) (res []influxpackage.Result, err error) { q := influxpackage.Query{ Command: cmd, Database: dbname, } if response, err := clnt.Query(q); err == nil { if response.Error() != nil { return res, response.Error() } res = response.Results } else { return res, err } return res, nil }
// dbCheck ensures the given database exists func dbCheck(conn client.Client, database string) error { if len(database) == 0 { return fmt.Errorf("no database specified") } q := client.Query{Command: "show databases"} resp, err := conn.Query(q) if err != nil { return err } for _, r := range resp.Results { for _, s := range r.Series { for _, v := range s.Values { for _, d := range v { if d.(string) == database { return nil } } } } } return fmt.Errorf("database %s does not exist", database) }