2020-01-14 10:38:55 +00:00
|
|
|
package semver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql/driver"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Scan implements the database/sql.Scanner interface.
|
|
|
|
func (v *Version) Scan(src interface{}) (err error) {
|
|
|
|
var str string
|
|
|
|
switch src := src.(type) {
|
|
|
|
case string:
|
|
|
|
str = src
|
|
|
|
case []byte:
|
|
|
|
str = string(src)
|
|
|
|
default:
|
2022-05-05 02:47:06 +00:00
|
|
|
return fmt.Errorf("version.Scan: cannot convert %T to string", src)
|
2020-01-14 10:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if t, err := Parse(str); err == nil {
|
|
|
|
*v = t
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Value implements the database/sql/driver.Valuer interface.
|
|
|
|
func (v Version) Value() (driver.Value, error) {
|
|
|
|
return v.String(), nil
|
|
|
|
}
|