-
Notifications
You must be signed in to change notification settings - Fork 399
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
pgdb: cover transactions with inTransaction
function to simplify error handling
#833
Conversation
Codecov Report
@@ Coverage Diff @@
## main #833 +/- ##
==========================================
+ Coverage 59.10% 59.37% +0.26%
==========================================
Files 218 218
Lines 9855 9833 -22
==========================================
+ Hits 5825 5838 +13
+ Misses 3320 3296 -24
+ Partials 710 699 -11
Flags with carried forward coverage won't be shown. Click here to find out more. |
@AlekSi @w84thesun please take a look at this quick fix. Let's not log errors if there are no errors (otherwise, the logs look quite confusing). |
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 think inTransaction
method makes it difficult to read the code, as you need to keep it in mind when you read other methods code. Maybe introducing function like finishTx(tx pgx.Tx, err error, method string)
would be enough?
inTransaction
function to simplify error handling
#844 was merged, please resolve merge conflicts and replace a few more |
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.
LGTM.
Description
Note: This PR might be hard to review, as a lot of lines of the
pgdb
package were changed. Let me know how I can help you with reviewing this PR.There is no special issue for this fix, but it's done as a part of ref #372.
inTransaction
As now we use transactions in many places, handling potential errors (when a transaction begins, commits or rollbacks) takes quite a lot of lines of code (:D) and requires some accuracy.
To simplify this approach, this PR offers an
inTransaction
function to "wrap" any function with a transaction.Querier
pgxtype.Querier
is introduced instead ofpgx.Tx
to unify function signatures.Dealing with errors
As some of the
pgdb
errors might be wrapped, the comparison of errors was refactored toerrors.Is
anderrors.As
instead of==
.Not in scope
This PR only offers a refactoring for the existing transactions, adding new transactions is not in the scope of this PR.
Readiness checklist
task all
, and it passed.bin/godoc -index -play -timestamps -http=127.0.0.1:6060
.