-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
database/sql: add error getter on sql.Row #35804
Comments
Hi @muhlemmer, could you provide a code example of the chaining that this API change would improve? /cc @bradfitz @kardianos |
Example 1:
Example 2 extends example 1:
I would like both the
So that I can pass this types as DB or Tx connetion objects to the ORM. Ultimately, a caller of my package's objects could replace:
With:
And keep the same chaining as the |
I see there is still a |
@muhlemmer Not at this time. Thanks. @kardianos Any thoughts on this? Thanks. |
The benefit I would cite to adding it would be it allows you to differentiate query errors from Scan errors and in a framework act appropriately to each. The two strikes against this proposal is that (1) it makes this less of a convenience method (expands use case rather then just using *Result for most use cases) and (2) I tend to make different types of abstractions then what is presented here. I'm fine with adding this. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Based on the discussion, this seems like a likely accept. Leaving open for a week for final comments. |
No final comments, so accepted. |
Change https://golang.org/cl/214317 mentions this issue: |
What version of Go are you using (
go version
)?This is a small feature request.
go/src/database/sql/sql.go
Lines 3093 to 3097 in 6f7b96f
At this moment
QueryRow()
variants only return a row, and as mentioned in the above comments, for easy chaining. This makes it a bit inconvenient to program againstQueryRow()
if one wants to check the error and return the Row as-is to a higher level caller. For instance, in my usecase I would like to wrapQueryRow()
in go routines against multiple hosts and return the first successful result.Would it be possible to have an error getter method (eg.
row.Err()
) on the thesql.Row
type? This way "chaining" is still possible, while giving also more control over the error checking mechanism.Edit: forgot to mention that I'm willing to implement this in a PR myself.
The text was updated successfully, but these errors were encountered: