Skip to content

Commit

Permalink
adjust PropertyMap test to drivers that may return string now instead…
Browse files Browse the repository at this point in the history
… of []byte as the base type for Scanners; a test-only change that has all tests passing again
  • Loading branch information
jmoiron committed Feb 28, 2018
1 parent 645fea9 commit bbb9b6b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sqlx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1387,13 +1387,17 @@ func (p PropertyMap) Value() (driver.Value, error) {

func (p PropertyMap) Scan(src interface{}) error {
v := reflect.ValueOf(src)
if !v.IsValid() || v.IsNil() {
if !v.IsValid() || v.CanAddr() && v.IsNil() {
return nil
}
if data, ok := src.([]byte); ok {
return json.Unmarshal(data, &p)
switch ts := src.(type) {
case []byte:
return json.Unmarshal(ts, &p)
case string:
return json.Unmarshal([]byte(ts), &p)
default:
return fmt.Errorf("Could not not decode type %T -> %T", src, p)
}
return fmt.Errorf("Could not not decode type %T -> %T", src, p)
}

func TestEmbeddedMaps(t *testing.T) {
Expand Down

0 comments on commit bbb9b6b

Please sign in to comment.