From bfba7d7dba1bd101866629e315ce9e1dc786e422 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Thu, 16 May 2024 18:36:27 +0200 Subject: [PATCH 1/2] Implement the Scan and driver.Value SQL interfaces --- version.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/version.go b/version.go index e87df69..e4e30d5 100644 --- a/version.go +++ b/version.go @@ -2,6 +2,7 @@ package version import ( "bytes" + "database/sql/driver" "fmt" "reflect" "regexp" @@ -160,7 +161,7 @@ func (v *Version) Compare(other *Version) int { // this means Other had the lower specificity // Check to see if the remaining segments in Self are all zeros - if !allZero(segmentsSelf[i:]) { - //if not, it means that Self has to be greater than Other + // if not, it means that Self has to be greater than Other return 1 } break @@ -405,3 +406,20 @@ func (v *Version) UnmarshalText(b []byte) error { func (v *Version) MarshalText() ([]byte, error) { return []byte(v.String()), nil } + +// Scan implements the sql.Scanner interface. +func (v *Version) Scan(src interface{}) error { + switch src := src.(type) { + case string: + return v.UnmarshalText([]byte(src)) + case nil: + return nil + default: + return fmt.Errorf("Cannot scan %T as Version", src) + } +} + +// Value implements the driver.Valuer interface. +func (v *Version) Value() (driver.Value, error) { + return v.String(), nil +} From 511a12401e6b51be4dec3fea0e1c9192297fc8c8 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Wed, 22 May 2024 16:57:23 +0200 Subject: [PATCH 2/2] Update version.go --- version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.go b/version.go index e4e30d5..90444a1 100644 --- a/version.go +++ b/version.go @@ -415,7 +415,7 @@ func (v *Version) Scan(src interface{}) error { case nil: return nil default: - return fmt.Errorf("Cannot scan %T as Version", src) + return fmt.Errorf("cannot scan %T as Version", src) } }