New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: database/sql: add interface for Scan method on Row and Rows #33786
Comments
CC @kardianos |
If I was to guess, you are manually hydrating each struct item through a method. That's an interesting method. I assume you are doing something like this:
Can you confirm? |
Yeah that's right |
A full example would look something like this
|
Thank you for the use case.
I could easily see an interface defined as:
But this isn't to say your version would be worse or better, but I would perceive the value is more application dependent. So if you choose to marshal data in this way, make a common package that defines it for you. I think a RowScanner would have some value, but I don't think it would pull its own weight. |
Problem
Every time that I start a new project that uses
database/sql
I end up creating an interface for theScan
method that is present on bothsql.Row
andsql.Rows
this allows me to make a function that accepts bothsql.Row
andsql.Rows
and uses theScan
method to populate a struct.Solution
I feel like this interface should be present in the
database/sql
package rather than it being defined by me.The text was updated successfully, but these errors were encountered: