ScanStruct support for structs with Interface types#399
Draft
arkamar wants to merge 2 commits into
Draft
Conversation
This commit adds a currently failing test case demonstrating an issue when a struct containing an item of type sql.Scanner is used. The test fails with the error: sql: Scan error on column index 0, name "value": unsupported Scan, storing driver.Value type string into type *sql.Scanner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
ScanStructmethod ofgoqu. The method encounters errors when dealing with structs that contain interface types, specifically those implementing thesql.Scannerinterface.The
ScanStructmethod fails with errors like the following when it encounters an interface type within a struct:This issue arises because the
newColumnMapfunction assigns the interface type toGoTyperather 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
Interfaceand then replacingf.TypewithconcreteType. 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 withNullInt32object).Well, the question is, if I am not overthinking it :)
So, what do you think?