2020-08-09 15:29:54 -07: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:
|
2024-05-24 14:08:09 -07:00
|
|
|
return fmt.Errorf("version.Scan: cannot convert %T to string", src)
|
2020-08-09 15:29:54 -07: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
|
|
|
|
}
|