Skip to content

Commit

Permalink
Move the custom nil-checking logic to decodeCursor
Browse files Browse the repository at this point in the history
  • Loading branch information
zitnik committed Feb 16, 2024
1 parent 8ff8a42 commit 82daeea
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion paginator/paginator.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,19 @@ func (p *Paginator) decodeCursor(dest interface{}) (result []interface{}, err er
}
// replace null values
for i := range result {
if isNil(result[i]) {
var isNullValue bool
// for custom types, evaluate isNil on the underlying value
if ct, ok := result[i].(cursor.CustomType); ok && p.rules[i].CustomType != nil {
val, valErr := ct.GetCustomTypeValue(p.rules[i].CustomType.Meta)
if valErr != nil {
err = valErr
}
isNullValue = isNil(val)
} else {
isNullValue = isNil(result[i])
}

if isNullValue {
result[i] = p.rules[i].NULLReplacement
}
}
Expand Down

0 comments on commit 82daeea

Please sign in to comment.