From 99ccac59486336902e28e7588b46e63916631c2e Mon Sep 17 00:00:00 2001 From: Pavel Merzlyakov Date: Mon, 3 Oct 2022 14:27:21 +0300 Subject: [PATCH] implemented scanner, valuer interfaces --- sql.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 sql.go diff --git a/sql.go b/sql.go new file mode 100644 index 0000000..6f373e0 --- /dev/null +++ b/sql.go @@ -0,0 +1,26 @@ +package versioning + +import ( + "database/sql/driver" + + "github.com/pkg/errors" +) + +func (v *Version) Scan(value interface{}) error { + switch code := value.(type) { + case int64: + parsed, err := ParseFromCode(uint32(code)) + if err != nil { + return err + } + + *v = parsed + return nil + default: + return errors.Errorf("incompatible version code type - %T", value) + } +} + +func (v Version) Value() (driver.Value, error) { + return int64(v.Code()), nil +}