Skip to content

Commit

Permalink
Fix custom DB type scan failing when nil.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Feb 5, 2022
1 parent 48ef3dc commit 8fb459d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ func (s SubscriberAttribs) Value() (driver.Value, error) {

// Scan unmarshals JSONB from the DB.
func (s SubscriberAttribs) Scan(src interface{}) error {
if src == nil {
s = make(SubscriberAttribs)
return nil
}

if data, ok := src.([]byte); ok {
return json.Unmarshal(data, &s)
}
Expand All @@ -333,6 +338,11 @@ func (s SubscriberAttribs) Scan(src interface{}) error {

// Scan unmarshals JSONB from the DB.
func (s StringIntMap) Scan(src interface{}) error {
if src == nil {
s = make(StringIntMap)
return nil
}

if data, ok := src.([]byte); ok {
return json.Unmarshal(data, &s)
}
Expand Down

0 comments on commit 8fb459d

Please sign in to comment.