Skip to content
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

Merged
merged 4 commits into from
Mar 4, 2025
Merged

feat: [#358] Implement Transaction methods #933

merged 4 commits into from
Mar 4, 2025

Conversation

hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Mar 3, 2025

πŸ“‘ Description

goravel/goravel#358

@coderabbitai summary

βœ… Checks

  • Added test cases for my code

Copy link

codecov bot commented Mar 3, 2025

Codecov Report

All modified and coverable lines are covered by tests βœ…

Project coverage is 69.16%. Comparing base (279fdf5) to head (1f412e7).
Report is 3 commits behind head on master.

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.
πŸ“’ Have feedback on the report? Share it here.

@hwbrzzl hwbrzzl marked this pull request as ready for review March 4, 2025 01:58
@Copilot Copilot bot review requested due to automatic review settings March 4, 2025 01:58
@hwbrzzl hwbrzzl requested a review from a team as a code owner March 4, 2025 01:58

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)
@hwbrzzl hwbrzzl merged commit da297ba into master Mar 4, 2025
14 checks passed
@hwbrzzl hwbrzzl deleted the bowen/#358-12 branch March 4, 2025 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant