mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 21:52:43 +08:00
Chore: replace xorm by sqlx in dashboardversion service (#53869)
This commit is contained in:
@ -7,6 +7,7 @@ package simplejson
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -38,6 +39,27 @@ func (j *Json) ToDB() ([]byte, error) {
|
||||
return j.Encode()
|
||||
}
|
||||
|
||||
func (j *Json) Scan(val interface{}) error {
|
||||
switch v := val.(type) {
|
||||
case []byte:
|
||||
if len(v) == 0 {
|
||||
return nil
|
||||
}
|
||||
return json.Unmarshal(v, &j)
|
||||
case string:
|
||||
if len(v) == 0 {
|
||||
return nil
|
||||
}
|
||||
return json.Unmarshal([]byte(v), &j)
|
||||
default:
|
||||
return fmt.Errorf("unsupported type: %T", v)
|
||||
}
|
||||
}
|
||||
|
||||
func (j *Json) Value() (driver.Value, error) {
|
||||
return j.ToDB()
|
||||
}
|
||||
|
||||
// NewJson returns a pointer to a new `Json` object
|
||||
// after unmarshaling `body` bytes
|
||||
func NewJson(body []byte) (*Json, error) {
|
||||
|
Reference in New Issue
Block a user