-
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
database/sql: don't encumber Context with options #18284
Comments
I think in order for this to be considered we need a proposal that also encompasses how to handle options for the other methods that also take a context today (QueryContext, QueryRowContext, ExecContext, PrepareContext). |
But those (AFAIK) does not use ReadOnly/IsolationLevel! And I don't have a good solution for passing option in the other context functions... |
I don't see how the QueryContext, QueryRowContext, And ExecContext could be chagned to take an options. If the pattern was to make a sql.Cmd and pass that in, we would have room for that. As it stands I don't think we should change those signatures. I was mainly relying to a previous question when I mentioned that. The only way I could see is if we had a strong use case to pass query specific options maybe we could allow a specific Option type to the argument list at a future date. For BeginContext I am personally fine with For the sake of exploration because go1.8 has not entirely shipped yet (though the timing is very late), maybe we could do the following:
This would allow drivers to define custom attributes for transactions. In the original issue that was one of the sticking points. At this point we have just re-created the context value setting. Again, I'm not thrilled with a change this late, but let me know what you think of that counter proposal, I'll also cc @bradfitz to see what he says about the API / API changes at this point in time. |
I think context is designed to be propagated downward (possibly as child contexts). It seems unexpected to me as a library-author that clients of my library can modify the isolation level in my db accesses without me ever mentioning the phrase "IsolationLevel" in my code. The context design seems to inadvertently expose API to transitive callers, rather than just to immediate callers. |
@balasanjay If you don't want to affect downstream then don't pass on the ctx you use to set the iso level. I don't see this as a pragmatic issue (I could be wrong), but I do agree that this is less than idiomatic. I could envision using it either at the call site or like:
Maybe that would be a bad idea and should be an anti-pattern. But I think it might be just fine. I'm mainly looking for concrete alternative API designs and technical acceptance or critique of any suggested. It is important to note that this was previously discussed publicly on the issue tracker: #15123 (comment) I don't know if it is too late to make such a change. But it might be possible if there is a compelling complete alternative that is superior. Please read the linked issue, and comment on any full proposals stated here. |
I do like the I'd like to have @bradfitz suggest something regarding this, as he has designed more APIs than all of us... |
Potential API change:
Feedback requested from interested parties. |
Yup, SGTM. (Background: Russ, Ian and I chatted about this at the Go 1.8 release meeting, and then I chatted with @kardianos about it after.) |
Quick question. Why are we defining TxOpt twice: once in the sql and another time in the driver package? |
package driver must not reference package sql. User needs to ref struct in sql, driver needs it in driver. This is one of these cases where I'd like the alias feature. But for now we have duplicate definitions. |
That makes sense. Thanks @kardianos. |
CL https://golang.org/cl/34330 mentions this issue. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go1.8beta1
What operating system and processor architecture are you using (
go env
)?linux/amd64
What did you do?
See https://groups.google.com/forum/#!topic/golang-nuts/20NtIGTgBeg
What did you expect to see?
A nice, clean API just as before, and not using context.Context for transferring options.
What did you see instead?
ReadOnlyContext and IsolationContext to passes isolation level and readonly flag in the Context.
I'd modify BeginContext as
This does not block anybody to use the Context as bag-of-values, but at least does not encourage that.
The text was updated successfully, but these errors were encountered: