feat(Type): add time.Time as a possible type for Scan

This commit is contained in:
2024-12-31 17:58:13 +01:00
parent 1ab0570883
commit b5fc0df93b
2 changed files with 34 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package Type
import (
"database/sql"
"fmt"
"time"
Assert "github.com/lbatuska/goutils/assert"
)
@@ -201,6 +202,21 @@ func (opt *Optional[T]) Scan(src interface{}) error {
opt.present = true
return nil
}
case *time.Time:
if t, ok := src.(time.Time); ok {
*v = t
opt.present = true
return nil
}
if b, ok := src.([]byte); ok {
parsedTime, err := time.Parse(time.RFC3339, string(b))
if err == nil {
*v = parsedTime
opt.present = true
return nil
}
}
}
// We couldnt parse the value
opt.present = false