Skip to content

Commit

Permalink
Fix byte scan
Browse files Browse the repository at this point in the history
  • Loading branch information
nullbio committed Nov 12, 2016
1 parent b49443b commit 41a31fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions byte.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"database/sql/driver"
"encoding/json"
"errors"

"gopkg.in/nullbio/null.v6/convert"
)

// Byte is an nullable int.
Expand Down Expand Up @@ -115,8 +113,17 @@ func (b *Byte) Scan(value interface{}) error {
b.Byte, b.Valid = 0, false
return nil
}

val := value.(string)
if len(val) == 0 {
b.Valid = false
b.Byte = 0
return nil
}

b.Valid = true
return convert.ConvertAssign(&b.Byte, value)
b.Byte = byte(val[0])
return nil
}

// Value implements the driver Valuer interface.
Expand Down
2 changes: 1 addition & 1 deletion byte_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestByteSetValid(t *testing.T) {

func TestByteScan(t *testing.T) {
var i Byte
err := i.Scan('b')
err := i.Scan("b")
maybePanic(err)
assertByte(t, i, "scanned int")

Expand Down

0 comments on commit 41a31fc

Please sign in to comment.