You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
545 B
Go

package types
import (
"bytes"
"database/sql/driver"
"encoding/json"
"errors"
)
type JsonMap map[string]interface{}
func (m *JsonMap) Scan(src interface{}) error {
val, ok := src.([]byte)
if !ok {
return errors.New("not []byte")
}
jsonDecoder := json.NewDecoder(bytes.NewBuffer(val))
err := jsonDecoder.Decode(m)
if err != nil {
return err
}
return nil
}
func (m JsonMap) Value() (driver.Value, error) {
val, err := json.Marshal(m)
if err != nil {
return driver.Value(nil), err
}
return driver.Value(val), nil
}