-
Notifications
You must be signed in to change notification settings - Fork 91
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
feat: [#358] Implement Transaction methods #933
Conversation
Codecov ReportAll modified and coverable lines are covered by tests β
Additional details and impacted files@@ Coverage Diff @@
## master #933 +/- ##
==========================================
+ Coverage 68.82% 69.16% +0.33%
==========================================
Files 154 157 +3
Lines 10200 10519 +319
==========================================
+ Hits 7020 7275 +255
- Misses 2857 2911 +54
- Partials 323 333 +10 β View full report in Codecov by Sentry. |
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.
PR Overview
This PR implements transaction methods for the database, adding support for explicit transaction handling (BeginTransaction, Commit, Rollback) and a Transaction helper that wraps operations in a transaction. The changes include new test cases for transactions, updates to mocks to support transaction methods, and modifications to production code (DB and Query implementations) to integrate transaction logging and nested query handling.
Reviewed Changes
File | Description |
---|---|
tests/db_test.go | Adds tests for transaction behaviors including commit and rollback. |
mocks/database/db/DB.go | Implements mock functions for BeginTransaction, Commit, Rollback, and Transaction. |
database/db/db.go | Updates DB struct and methods to support transactions, including changes to NewDB and BuildDB functions. |
database/db/query.go | Modifies query construction to pass along transaction logs and refines nested query callback signatures. |
database/db/utils.go | Introduces the TxLog type for logging transaction operations. |
tests/query.go | Updates test setup code to use the new NewDB signature with transaction parameters. |
contracts/database/db/db.go | Updates the DB and Query interfaces to include transaction methods and return types. |
database/db/query_test.go | Adjusts tests for query methods to supply the expected txLogs parameter to NewQuery. |
errors/list.go | Adds a new error (DatabaseTransactionNotStarted) for when commit or rollback are called without a transaction. |
database/db/db_test.go | Updates tests to invoke NewDB with the additional transaction-related parameters. |
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (3)
tests/db_test.go:448
- Comparing errors directly with '==' may not reliably detect wrapped errors; consider using errors.Is(err, sql.ErrNoRows) for a more robust error comparison.
s.Equal(sql.ErrNoRows, err)
database/db/db.go:59
- Passing nil for the db parameter in BeginTransaction assumes that subsequent query operations will rely solely on the transaction; please verify that any access to the db field is safely guarded to avoid nil pointer issues.
return NewDB(r.ctx, r.config, r.driver, r.log, nil, tx, &[]TxLog{})
database/db/query.go:768
- The type assertion here assumes that the callback always returns a *Query; consider adding safeguards or documenting that callbacks must return a *Query to prevent potential panics.
nestedQuery = query(nestedQuery).(*Query)
π Description
goravel/goravel#358
@coderabbitai summary
β Checks