Skip to content

Commit

Permalink
add more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenafamo committed Jan 2, 2023
1 parent de74de6 commit 2be7892
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion mapper_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func WithScannableTypes(scannableTypes ...any) MappingSourceOption {
if st == nil {
return fmt.Errorf("scannable type must be a pointer, got %T", stOpt)
}
if st.Kind() != reflect.Ptr {
if st.Kind() != reflect.Pointer {
return fmt.Errorf("scannable type must be a pointer, got %s: %s",
st.Kind(), st.String())
}
Expand Down
21 changes: 8 additions & 13 deletions row.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,23 @@ type Row struct {
allowUnknown bool
}

// ScheduleScan schedules a scan for the column name into the given value
// val should be a pointer
func (r *Row) ScheduleScan(colName string, val any) {
r.ScheduleScanx(colName, reflect.ValueOf(val))
}

// ScheduleScanx schedules a scan for the column name into the given reflect.Value
// val.Kind() should be reflect.Pointer
func (r *Row) ScheduleScanx(colName string, val reflect.Value) {
colIndex := r.index(colName)
if colIndex == -1 {
r.unknownDestinations = append(r.unknownDestinations, colName)
return
}

r.scanDestinations[colIndex] = val
}

func (r *Row) index(name string) int {
for i, n := range r.columns {
if name == n {
return i
if n == colName {
r.scanDestinations[i] = val
return
}
}

return -1
r.unknownDestinations = append(r.unknownDestinations, colName)
}

// To get a copy of the columns to pass to mapper generators
Expand Down

0 comments on commit 2be7892

Please sign in to comment.