diff --git a/type/optional.go b/type/optional.go index a6e0f77..19e17b4 100644 --- a/type/optional.go +++ b/type/optional.go @@ -125,8 +125,15 @@ func (opt *Optional[T]) Scan(src interface{}) error { return nil } - // If T is a scanner - if scanner, ok := any(opt.value).(sql.Scanner); ok { + // If T is a scanner (Scan is usually implemented on pointers so we need a pointer) + var scanner sql.Scanner = nil + var ok bool = false + if reflect.TypeOf(opt.value).Kind() == reflect.Ptr { + scanner, ok = any(opt.value).(sql.Scanner) + } else { + scanner, ok = any(&opt.value).(sql.Scanner) + } + if ok { if err := scanner.Scan(src); err != nil { return err } diff --git a/type/result.go b/type/result.go index 57a8d72..9402769 100644 --- a/type/result.go +++ b/type/result.go @@ -151,8 +151,15 @@ func (res *Result[T]) Scan(src interface{}) error { return nil } - // If T is a scanner - if scanner, ok := any(res.value).(sql.Scanner); ok { + // If T is a scanner (Scan is usually implemented on pointers so we need a pointer) + var scanner sql.Scanner = nil + var ok bool = false + if reflect.TypeOf(res.value).Kind() == reflect.Ptr { + scanner, ok = any(res.value).(sql.Scanner) + } else { + scanner, ok = any(&res.value).(sql.Scanner) + } + if ok { if err := scanner.Scan(src); err != nil { return err }