aboutsummaryrefslogblamecommitdiffhomepage
path: root/vendor/github.com/blang/semver/sql.go
blob: eb4d802666e0bd29f3a36d7a2af63d62796f992e (plain) (tree)





























                                                                                    
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:
		return fmt.Errorf("Version.Scan: cannot convert %T to string.", src)
	}

	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
}