database/models: MetadataMap decodes from string
github.com/lib/pq began decoding text-like fields as strings to Scanners. See lib/pq@e2402a7cd1
This commit is contained in:
parent
35df9d5846
commit
0305dde964
@ -83,11 +83,16 @@ type Vulnerability struct {
|
|||||||
type MetadataMap map[string]interface{}
|
type MetadataMap map[string]interface{}
|
||||||
|
|
||||||
func (mm *MetadataMap) Scan(value interface{}) error {
|
func (mm *MetadataMap) Scan(value interface{}) error {
|
||||||
val, ok := value.([]byte)
|
if value == nil {
|
||||||
if !ok {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return json.Unmarshal(val, mm)
|
|
||||||
|
// github.com/lib/pq decodes TEXT/VARCHAR fields into strings.
|
||||||
|
val, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
panic("got type other than []byte from database")
|
||||||
|
}
|
||||||
|
return json.Unmarshal([]byte(val), mm)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mm *MetadataMap) Value() (driver.Value, error) {
|
func (mm *MetadataMap) Value() (driver.Value, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user