Fix byte scan

This commit is contained in:
Patrick O'brien 2016-11-12 13:40:11 +10:00
parent b49443bac4
commit 41a31fc048
2 changed files with 11 additions and 4 deletions

13
byte.go
View file

@ -5,8 +5,6 @@ import (
"database/sql/driver"
"encoding/json"
"errors"
"gopkg.in/nullbio/null.v6/convert"
)
// Byte is an nullable int.
@ -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.

View file

@ -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")