Skip to content

Commit

Permalink
database/models: MetadataMap decodes from string
Browse files Browse the repository at this point in the history
github.com/lib/pq began decoding text-like fields as strings to
Scanners.

See lib/pq@e2402a7
  • Loading branch information
jzelinskie committed May 6, 2017
1 parent 35df9d5 commit 0305dde
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions database/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0305dde

Please sign in to comment.