fix Scanner implementation
This commit is contained in:
parent
99ccac5948
commit
35e0da91ca
23
sql.go
23
sql.go
|
@ -2,23 +2,36 @@ package versioning
|
|||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"strconv"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (v *Version) Scan(value interface{}) error {
|
||||
switch code := value.(type) {
|
||||
var code uint32
|
||||
|
||||
switch val := value.(type) {
|
||||
case []byte:
|
||||
c, err := strconv.ParseUint(string(val), 10, 32)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
code = uint32(c)
|
||||
|
||||
case int64:
|
||||
parsed, err := ParseFromCode(uint32(code))
|
||||
code = uint32(val)
|
||||
|
||||
default:
|
||||
return errors.Errorf("incompatible version code type - %T", value)
|
||||
}
|
||||
|
||||
parsed, err := ParseFromCode(code)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*v = parsed
|
||||
return nil
|
||||
default:
|
||||
return errors.Errorf("incompatible version code type - %T", value)
|
||||
}
|
||||
}
|
||||
|
||||
func (v Version) Value() (driver.Value, error) {
|
||||
|
|
Loading…
Reference in New Issue