feat: add txn interceptor with gorm v2#487
Merged
chinmayb merged 1 commit intoinfobloxopen:masterfrom Sep 18, 2025
Merged
Conversation
chinmayb
commented
Sep 18, 2025
| func (m *mockServerStream) SendMsg(interface{}) error { return nil } | ||
| func (m *mockServerStream) RecvMsg(interface{}) error { return nil } | ||
|
|
||
| func TestStreamServerInterceptor(t *testing.T) { |
Contributor
Author
There was a problem hiding this comment.
additional test cases for stream interceptor is added
amaskalenka
approved these changes
Sep 18, 2025
Contributor
amaskalenka
left a comment
There was a problem hiding this comment.
LGTM
You can also leverage db.Transaction method to get rid of the custom code for Commit and Rollback
var resp interface{}
terr := db.Transaction(func(tx *gorm.DB) error {
ctx = NewContext(ctx, txn)
r, err := handler(ctx, req)
if err != nil {
return err
}
resp = r
return nil
})
if terr != nil {
return nil, err
}
return resp, nil
Contributor
Author
|
@amaskalenka Good point! I will take it up as improvement and add it as a separate PR as I'd need to modify tests. |
yvardhineni
approved these changes
Sep 18, 2025
Contributor
Author
|
@amaskalenka just noticed that, there are commitHooks, that support will be lost if we use db.Transaction. So its better to keep it as it is ?
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a copy paste of https://github.com/infobloxopen/atlas-app-toolkit/blob/master/gorm/transaction.go
but using gorm.io library.