mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
mysql: commented out old code from old PR
This commit is contained in:
parent
8f90c6115d
commit
00fcaaf171
@ -3,10 +3,8 @@ package mysql
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/go-xorm/core"
|
|
||||||
"github.com/go-xorm/xorm"
|
"github.com/go-xorm/xorm"
|
||||||
"github.com/grafana/grafana/pkg/log"
|
"github.com/grafana/grafana/pkg/log"
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
@ -82,79 +80,79 @@ func (e *MysqlExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice, co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getData(db *core.DB, req *sqlDataRequest) (interface{}, error) {
|
// func getData(db *core.DB, req *sqlDataRequest) (interface{}, error) {
|
||||||
queries := strings.Split(req.Query, ";")
|
// queries := strings.Split(req.Query, ";")
|
||||||
|
//
|
||||||
data := dataStruct{}
|
// data := dataStruct{}
|
||||||
data.Results = make([]resultsStruct, 1)
|
// data.Results = make([]resultsStruct, 1)
|
||||||
data.Results[0].Series = make([]seriesStruct, 0)
|
// data.Results[0].Series = make([]seriesStruct, 0)
|
||||||
|
//
|
||||||
for i := range queries {
|
// for i := range queries {
|
||||||
if queries[i] == "" {
|
// if queries[i] == "" {
|
||||||
continue
|
// continue
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
rows, err := db.Query(queries[i])
|
// rows, err := db.Query(queries[i])
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
defer rows.Close()
|
// defer rows.Close()
|
||||||
|
//
|
||||||
name := fmt.Sprintf("table_%d", i+1)
|
// name := fmt.Sprintf("table_%d", i+1)
|
||||||
series, err := arrangeResult(rows, name)
|
// series, err := arrangeResult(rows, name)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
data.Results[0].Series = append(data.Results[0].Series, series.(seriesStruct))
|
// data.Results[0].Series = append(data.Results[0].Series, series.(seriesStruct))
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return data, nil
|
// return data, nil
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
func arrangeResult(rows *core.Rows, name string) (interface{}, error) {
|
// func arrangeResult(rows *core.Rows, name string) (interface{}, error) {
|
||||||
columnNames, err := rows.Columns()
|
// columnNames, err := rows.Columns()
|
||||||
|
//
|
||||||
series := seriesStruct{}
|
// series := seriesStruct{}
|
||||||
series.Columns = columnNames
|
// series.Columns = columnNames
|
||||||
series.Name = name
|
// series.Name = name
|
||||||
|
//
|
||||||
for rows.Next() {
|
// for rows.Next() {
|
||||||
columnValues := make([]interface{}, len(columnNames))
|
// columnValues := make([]interface{}, len(columnNames))
|
||||||
|
//
|
||||||
err = rows.ScanSlice(&columnValues)
|
// err = rows.ScanSlice(&columnValues)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return nil, err
|
// return nil, err
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// bytes -> string
|
// // bytes -> string
|
||||||
for i := range columnValues {
|
// for i := range columnValues {
|
||||||
switch columnValues[i].(type) {
|
// switch columnValues[i].(type) {
|
||||||
case []byte:
|
// case []byte:
|
||||||
columnValues[i] = fmt.Sprintf("%s", columnValues[i])
|
// columnValues[i] = fmt.Sprintf("%s", columnValues[i])
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
series.Values = append(series.Values, columnValues)
|
// series.Values = append(series.Values, columnValues)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return series, err
|
// return series, err
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
type sqlDataRequest struct {
|
// type sqlDataRequest struct {
|
||||||
Query string `json:"query"`
|
// Query string `json:"query"`
|
||||||
Body []byte `json:"-"`
|
// Body []byte `json:"-"`
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
type seriesStruct struct {
|
// type seriesStruct struct {
|
||||||
Columns []string `json:"columns"`
|
// Columns []string `json:"columns"`
|
||||||
Name string `json:"name"`
|
// Name string `json:"name"`
|
||||||
Values [][]interface{} `json:"values"`
|
// Values [][]interface{} `json:"values"`
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
type resultsStruct struct {
|
// type resultsStruct struct {
|
||||||
Series []seriesStruct `json:"series"`
|
// Series []seriesStruct `json:"series"`
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
type dataStruct struct {
|
// type dataStruct struct {
|
||||||
Results []resultsStruct `json:"results"`
|
// Results []resultsStruct `json:"results"`
|
||||||
}
|
// }
|
||||||
|
Loading…
Reference in New Issue
Block a user