Hello everyone,
First of all, thanks to those who will take the time to read this post, and help me.
I try to develop a datasource which display informations from a mysql table.
Here is a view of the field I want to process (JSON format string) :
With this request, i can display the json in a table :
rows, err := mysql.QueryContext(ctx, "SELECT details FROM table")
frame := data.NewFrame("frameName")
frame.RefID = q.RefID
frame.Fields = append(frame.Fields, data.NewField("details", nil, []string{}))
for rows.Next() {
var s string
rows.Scan(&s)
frame.AppendRow(s)
}
return backend.DataResponse{
Frames: data.Frames{frame},
Error: nil,
}
It works, the JSON is shown in a table with one columns.
.
.
.
.
.
.
.
I want to explode my JSON string to show the different elements in different columns.
So I have created more fileds and used the UnmarshalJSON function, but the principe is the same :
rows, err := mysql.QueryContext(ctx, "SELECT details FROM table")
frame := data.NewFrame("frameName")
frame.RefID = q.RefID
frame.Fields = append(frame.Fields, data.NewField("counter1", nil, []int8{}))
frame.Fields = append(frame.Fields, data.NewField("counter2", nil, []int8{}))
frame.Fields = append(frame.Fields, data.NewField("counter3", nil, []int64{}))
for rows.Next() {
var s string
rows.Scan(&s)
frame.AppendRow(frame.UnmarshalJSON([]byte(s)))
}
return backend.DataResponse{
Frames: data.Frames{frame},
Error: nil,
}
I don’t understand wy it doesn’t work, is my dataframes not in the right format ?
I have “Metric request error” shown in my datasource :
Has anyone ever had this problem ?
Thank you for your patience and your help,
Nicolas