-
Notifications
You must be signed in to change notification settings - Fork 81
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
Add support for drivers with ConnBeginTx interface #214
base: master
Are you sure you want to change the base?
Conversation
if !ok { | ||
return nil, driver.ErrSkip | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need an extra driver config ?
Will this condition not take care of any driver not implementing `ConnBeginTx' ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure, it seems from this code that the go sql library will handle it differently if the interface is implemented or not
https://github.com/golang/go/blob/master/src/database/sql/ctxutil.go#L97-L135
As you can see from that code if the interface is not implemented there is a fallback that eventually returns
errors.New("sql: driver does not support read-only transactions")
Thats how I originally found this issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What i meant is do we need to create a new struct sqlCommenterConnWithTx
?
Can we just not implement BeginTx
for sqlCommenterConn
?
func (s *sqlCommenterConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {...}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that :).
It's mainly your call.
Doing so makes the code simpler but it may change the expected behavior for drivers that don't implement BeginTx
as the code in go library has a special handling for drivers that don't implement that interface.
Thanks @kostyay for this PR ! |
Did you decide which way you want to implement this? |
Yes, this way should be fine for now. |
@mickeyreiss Changes looks good. We may need to add some unit tests for the new changes to avoid regression. |
Some drivers implement the
ConnBeginTx
interface, without it its not possible to specify Isolation mode for queries in Postgres.So I've implemented it.
I wanted to keep the behavior the same for drivers that don't implement it (so database/sql will fail with the
driver does not support non-default isolation level
error)If you like this implementation let me know and I will add a test.