Skip to content

Commit

Permalink
types#UnixMilli.Scan(): Support (u)int64
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd committed Mar 13, 2024
1 parent aa79b35 commit 12311ee
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions pkg/types/unix_milli.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql/driver"
"encoding"
"encoding/json"
"github.com/pkg/errors"
"strconv"
"time"
)
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 12311ee

Please sign in to comment.