database/models: MetadataMap decodes from string

github.com/lib/pq began decoding text-like fields as strings to
Scanners.

See lib/pq@e2402a7cd1e57e08a576b94cdfed36ae30366545
pull/389/head
Jimmy Zelinskie 7 years ago
parent 35df9d5846
commit 0305dde964

@ -83,11 +83,16 @@ type Vulnerability struct {
type MetadataMap map[string]interface{}
func (mm *MetadataMap) Scan(value interface{}) error {
val, ok := value.([]byte)
if !ok {
if value == 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) {

Loading…
Cancel
Save