Chore: replace xorm by sqlx in dashboardversion service (#53869)

This commit is contained in:
ying-jeanne
2022-08-25 16:04:16 -05:00
committed by GitHub
parent 8deababa50
commit fd01161bcc
9 changed files with 278 additions and 142 deletions

View File

@ -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) {