implemented scanner, valuer interfaces
This commit is contained in:
parent
69d40059ff
commit
99ccac5948
|
@ -0,0 +1,26 @@
|
|||
package versioning
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
|
||||
"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
|
||||
}
|
||||
|
||||
*v = parsed
|
||||
return nil
|
||||
default:
|
||||
return errors.Errorf("incompatible version code type - %T", value)
|
||||
}
|
||||
}
|
||||
|
||||
func (v Version) Value() (driver.Value, error) {
|
||||
return int64(v.Code()), nil
|
||||
}
|
Loading…
Reference in New Issue