feat: add support for time.Duration write and scan

This commit is contained in:
Jackie 2021-10-21 18:26:20 +02:00
parent 0260525aa0
commit 2f1b74e20c
2 changed files with 9 additions and 0 deletions

View File

@ -105,6 +105,13 @@ func Scan(b []byte, v interface{}) error {
var err error var err error
*v, err = time.Parse(time.RFC3339Nano, util.BytesToString(b)) *v, err = time.Parse(time.RFC3339Nano, util.BytesToString(b))
return err return err
case *time.Duration:
n, err := util.ParseInt(b, 10, 64)
if err != nil {
return err
}
*v = time.Duration(n)
return nil
case encoding.BinaryUnmarshaler: case encoding.BinaryUnmarshaler:
return v.UnmarshalBinary(b) return v.UnmarshalBinary(b)
default: default:

View File

@ -98,6 +98,8 @@ func (w *Writer) WriteArg(v interface{}) error {
case time.Time: case time.Time:
w.numBuf = v.AppendFormat(w.numBuf[:0], time.RFC3339Nano) w.numBuf = v.AppendFormat(w.numBuf[:0], time.RFC3339Nano)
return w.bytes(w.numBuf) return w.bytes(w.numBuf)
case time.Duration:
return w.int(v.Nanoseconds())
case encoding.BinaryMarshaler: case encoding.BinaryMarshaler:
b, err := v.MarshalBinary() b, err := v.MarshalBinary()
if err != nil { if err != nil {