-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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: convertAssign should be exposed as DefaultConvertAssign #24258
Comments
I don't really know the process for small proposals like this -- if there is interest in this for an upcoming minor version release, I'm happy to work on a PR. |
cc @kardianos |
Related to #22544 , possibly a duplicate depending on how/if it gets resolved. |
Indeed, but it would be nice to not block this smaller-scope proposal on that larger one. |
As a counter proposal: If a type's Scan method returned "database/sql/driver".ErrSkip rather then returning the error it could continue on to attempt to assign using reflection. |
@awreece Hi, what do you think of my proposal above? |
I'm not quite sure how that achieves my use case:
My goal would be to |
Compare to the original proposal:
|
What type of |
In the example above it was an |
I got bit by this again today. The test case below fails. I believe it is becase I failed to mimic the behavior in
fails:
(the test case passes when I changed the scan method to use a copy of |
I filed a separate bug for the surprising behavior (#24492) but I think it is another illustration of the perils of not being able to call back to the standard library |
I'm fine exporting a new variable ("DefaultConvertAssign" or whatever) if @kardianos is. |
@kardianos, any thoughts? |
I would prefer not to do this so long as I can come up with a more comprehensive value scanning proposal. I've been working on a potential Go2 interface would look like, the biggest change has to do with scanning values and results. Ideally this could be opted in by Go1 drivers, then Go2 drivers would simply remove the extra old methods. I should have an answer in a day or two. |
Change https://golang.org/cl/107995 mentions this issue: |
@awreece I think I may be having a hard time understanding your final use case. Could you point me to some code about what you are doing or describe it here? Just a high level description would be fine. |
I don't quite know what you mean by my "final use case" -- is it the memory corruption test cast? #24492 is a dedicated bug filed for that behavior and probably a better place to discuss that. In short, all of these are the same use case for me:
The last test case is a reduced demonstration of one of the issues I've hit because I don't have access to the internal |
Two questions:
|
Q1) Absolutely I could just do My comment reads something like:
Q2) I do not want to copy/paste convertAssign -- it is under active development and I have no reliable way to maintain a fork! :) I would much rather work with the open source project than fork it and lose the collaborative benefits. |
I've sent a CL for #24492 . I don't want the extra burden of maintaining convertAssign as a public API. I'm going to ask you either continue using the type assert or copy the one function out of database/sql and check on it every couple of years to see if you need to update it. |
It would be nice for there to be a generic
convertAssign
method exposed a laDefaultParameterConvert
.For an example use case, I want to make a custom wrapper for
driver.Valuer
andsql.Scanner
that will store in the databasenull
when my object is the zero value (this allows me to use the "zero value means empty" idiom in proto3 and "null means empty" in sql).For the
driver.Valuer
side, this is simple: I check to see if the value is zero, and otherwise delegate toDefaultParameterConverter
:Unfortunately,
convertAssign
is not exposed, making the corresponding in Scan much harder:A savvy reader will note that the above code is not actually as robust as
convertAssign
in a myriad of ways:convertAssign
will allocate a new object and scan into it, if possible.sql.Scanner
,convertAssign
will call.Scan()
.#22544 is a related proposal, but it appears to be focused on performance/safety for driver, not improving the end user api here.
The text was updated successfully, but these errors were encountered: