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 Queryer interface #14674
Comments
In Go, interfaces are defined only when they're accepted, not when they're provided. You can define your own Querier interface if you need one, no? |
correct but seems like everyone defines it seems kind of silly. but fair point. |
Does everybody define it? Got examples? If there's evidence that it's widely used, we can add it. |
off the top of my head:
I'm sure I could dig up more examples potentially. squirrel has a few forks that most likely also use them. |
All those interfaces look different, though. It doesn't look like there's necessarily consensus. I think it's fine if people writing funcs like QueryRowWith (https://github.com/Masterminds/squirrel/blob/master/squirrel.go#L110) define the exact interface they want. |
I disagree, almost all of them roll up to allow you to use TX and DB interchangably when executing a query, I think the differences are superficial. but as I said pretty indifferent on whether its included. just thought I'd point it out. |
Well, we have |
A case i frequently run into is if i want to use DB and TX (created from that DB) interchangeably on prepared statements:
If i want to use that with a TX from
|
@danilobuerger Stmt would likely satisify the querier interface. |
@james-lawrence, Stmt doesn't take the query. It only takes @danilobuerger, there is only one thing in the |
crap missed that part =) |
The fact that Stmt is different from DB and Tx gives me pause. If we add an interface which is the intersection of DB and Tx, it seems to discourage use of prepared statements, if things in the ecosystem start requiring a It almost makes me think the interface should be of Anybody want to try that route and send a CL? |
@bradfitz sorry, i didn't add that:
|
@bradfitz I'll be happy to take a stab at it and see how it works in practice. |
We should be careful here. We just defined a bunch of new Context methods and there is debate if Tx should have a nesting Tx or RollbackTo and SavePoint methods. This would strongly flavor such an interface. |
This is a duplicate of #14468. |
seems like 90% of the time I'm interacting with a database most of my DB code doesn't care if i'm within a TX or not. often there are queries I'm executing in various places with different contexts, some of which require a transaction, some which don't. But I can't share the code without writing my own Queryer style interface. now granted its only a few lines, but it seems like this is something that should just be in the sql package itself.
I'm happy to do the work, submit the PR etc. just curious if there is any object to adding it and why.
The text was updated successfully, but these errors were encountered: