feat: [#358] Add Select, update, Insert, Delete methods#947
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #947 +/- ##
=======================================
Coverage 69.16% 69.16%
=======================================
Files 157 157
Lines 10519 10519
=======================================
Hits 7275 7275
Misses 2911 2911
Partials 333 333 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
PR Overview
This pull request refactors the database package to introduce a new Tx interface and context-aware methods by replacing the previous Exec, Get, Queryx, Select, and related calls with their context-aware counterparts (e.g. ExecContext, GetContext, QueryxContext, SelectContext). It also updates transaction handling throughout the mocks, tests, and core database implementation to ensure improved transaction management and context propagation.
Reviewed Changes
| File | Description |
|---|---|
| mocks/database/db/CommonBuilder.go | Introduces context-aware methods and several duplicate method definitions in the mock. |
| mocks/database/db/DB.go | Updates BeginTransaction signature to return db.Tx instead of db.DB and adjusts related call types. |
| tests/*, database/db/db.go, and others | Replaces legacy non-context-aware calls with context-aware versions in tests and implementation. |
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
📑 Description
goravel/goravel#358
This pull request includes significant changes to the database transaction handling and query execution in the
contracts/databasepackage. The changes introduce new interfaces and refactor existing code to improve transaction management and context handling for database operations.Transaction Handling Improvements:
contracts/database/db/db.go: Introduced a newTxinterface and refactored theDBinterface to include transaction methods, such asCommit,Rollback, and various query execution methods. TheBeginTransactionmethod now returns aTxinstead ofDB, and a newTransactionmethod was added to execute transactions with a callback. [1] [2] [3] [4]Context Handling Enhancements:
contracts/database/db/db.go: Added methods to handle context in query execution, such asWithContext, and refactored existing methods to use context-aware query execution. [1] [2] [3] [4] [5]Query Execution Refactoring:
contracts/database/db/query.go: Refactored theQuerystruct to use the newCommonBuilderinterface for context-aware query execution methods. Updated methods likeCount,Cursor,Delete,First,FirstOr,FirstOrFail,Get,Insert, andUpdateto use context-aware execution. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]Test Updates:
database/db/db_test.goanddatabase/db/query_test.go: Updated tests to reflect the changes in transaction handling and context-aware query execution. [1] [2] [3] [4] [5] [6] [7]These changes enhance the flexibility and robustness of database operations by introducing better transaction management and context handling.
✅ Checks