From 35e0da91ca62a2822c85d9daed5b37c1face196a Mon Sep 17 00:00:00 2001 From: Pavel Merzlyakov Date: Mon, 3 Oct 2022 17:42:28 +0300 Subject: [PATCH] fix Scanner implementation --- sql.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/sql.go b/sql.go index 6f373e0..35d234c 100644 --- a/sql.go +++ b/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) { - case int64: - parsed, err := ParseFromCode(uint32(code)) - if err != nil { - return err - } + 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: + code = uint32(val) - *v = parsed - return nil default: return errors.Errorf("incompatible version code type - %T", value) } + + parsed, err := ParseFromCode(code) + if err != nil { + return err + } + + *v = parsed + return nil } func (v Version) Value() (driver.Value, error) {