ScanStruct support for structs with Interface types #399
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR serves both as an issue report and a preliminary attempt to fix a problem in the
ScanStruct
method ofgoqu
. The method encounters errors when dealing with structs that contain interface types, specifically those implementing thesql.Scanner
interface.The
ScanStruct
method fails with errors like the following when it encounters an interface type within a struct:This issue arises because the
newColumnMap
function assigns the interface type toGoType
rather than the concrete type of the object in use.I've made an attempt to resolve this by detecting if a struct field's type is
Interface
and then replacingf.Type
withconcreteType
. This approach seems to work, but it introduces a potential issue where the scanner might reuse the same type for subsequent scans, when the interface could be implemented by different objects (the second testcase withNullInt32
object).Well, the question is, if I am not overthinking it :)
So, what do you think?