File: sql.go

package info (click to toggle)
golang-github-blang-semver 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, experimental, sid
  • size: 176 kB
  • sloc: makefile: 3
file content (30 lines) | stat: -rw-r--r-- 555 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
}