Skip to content

Commit

Permalink
Add a way to scan a reflect.Value
Browse files Browse the repository at this point in the history
It receives a reflect.Value as reference and sets the value into it.
This change helps implementing ORMs.

closes chaisql#520
  • Loading branch information
dcu committed Jan 29, 2024
1 parent ef91bb4 commit 33fa14b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions internal/object/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ func Scan(d types.Object, targets ...interface{}) error {
target := targets[i]
i++

ref := reflect.ValueOf(target)
if !ref.IsValid() {
return &ErrUnsupportedType{target, fmt.Sprintf("Parameter %d is not valid", i)}
ref, ok := target.(reflect.Value)
if !ok {
ref = reflect.ValueOf(target)
if !ref.IsValid() {
return &ErrUnsupportedType{target, fmt.Sprintf("Parameter %d is not valid", i)}
}
}

return scanValue(v, ref)
Expand Down

0 comments on commit 33fa14b

Please sign in to comment.