File: sql.go

package info (click to toggle)
golang-bugst-relaxed-semver 0.15.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 260 kB
  • sloc: makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,108 bytes parent folder | download
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// Copyright 2018-2025 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//

package semver

import (
	"database/sql/driver"
	"fmt"
)

// Scan implements the sql.Scanner interface
func (v *Version) Scan(value interface{}) error {
	raw, ok := value.(string)
	if !ok {
		return fmt.Errorf("incompatible type %T for Version", value)
	}

	v.raw = raw
	v.bytes = []byte(v.raw)
	if err := parse(v); err != nil {
		return err
	}
	return nil
}

// Value implements the driver.Valuer interface
func (v *Version) Value() (driver.Value, error) {
	return v.raw, nil
}

// Scan implements the sql.Scanner interface
func (v *RelaxedVersion) Scan(value interface{}) error {
	raw, ok := value.(string)
	if !ok {
		return fmt.Errorf("incompatible type %T for Version", value)
	}

	res := ParseRelaxed(raw)
	*v = *res
	return nil
}

// Value implements the driver.Valuer interface
func (v *RelaxedVersion) Value() (driver.Value, error) {
	if v.version != nil {
		return v.version.raw, nil
	}
	return string(v.customversion), nil
}