From 12311ee76a785ae8a258d1e16dbaa6b062c480e5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 13 Mar 2024 17:08:25 +0100 Subject: [PATCH] `types#UnixMilli.Scan()`: Support `(u)int64` --- pkg/types/unix_milli.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pkg/types/unix_milli.go b/pkg/types/unix_milli.go index d68c12df..e0b780ab 100644 --- a/pkg/types/unix_milli.go +++ b/pkg/types/unix_milli.go @@ -5,6 +5,7 @@ import ( "database/sql/driver" "encoding" "encoding/json" + "github.com/pkg/errors" "strconv" "time" ) @@ -63,13 +64,23 @@ func (t *UnixMilli) Scan(src interface{}) error { return nil } - i, err := strToInt(string(src.([]byte))) - if err != nil { - return err + switch v := src.(type) { + case []byte: + i, err := strToInt(string(src.([]byte))) + if err != nil { + return err + } + + *t = UnixMilli(time.UnixMilli(i)) + // https://github.com/go-sql-driver/mysql/pull/1452 + case uint64: + *t = UnixMilli(time.UnixMilli(int64(v))) + case int64: + *t = UnixMilli(time.UnixMilli(v)) + default: + return errors.Errorf("bad (u)int64/[]byte type assertion from %[1]v (%[1]T)", src) } - *t = UnixMilli(FromUnixMilli(i)) - return nil }