Skip to content

feat: [#358] Add Select, update, Insert, Delete methods#947

Merged
hwbrzzl merged 6 commits intomasterfrom
bowen/#358-18
Mar 8, 2025
Merged

feat: [#358] Add Select, update, Insert, Delete methods#947
hwbrzzl merged 6 commits intomasterfrom
bowen/#358-18

Conversation

@hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Mar 8, 2025

📑 Description

goravel/goravel#358

This pull request includes significant changes to the database transaction handling and query execution in the contracts/database package. 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 new Tx interface and refactored the DB interface to include transaction methods, such as Commit, Rollback, and various query execution methods. The BeginTransaction method now returns a Tx instead of DB, and a new Transaction method was added to execute transactions with a callback. [1] [2] [3] [4]

Context Handling Enhancements:

Query Execution Refactoring:

  • contracts/database/db/query.go: Refactored the Query struct to use the new CommonBuilder interface for context-aware query execution methods. Updated methods like Count, Cursor, Delete, First, FirstOr, FirstOrFail, Get, Insert, and Update to use context-aware execution. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

Test Updates:

  • database/db/db_test.go and database/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

  • Added test cases for my code

@codecov
Copy link

codecov bot commented Mar 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.16%. Comparing base (cabc06d) to head (b559449).
Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hwbrzzl hwbrzzl marked this pull request as ready for review March 8, 2025 12:22
Copilot AI review requested due to automatic review settings March 8, 2025 12:22
@hwbrzzl hwbrzzl requested a review from a team as a code owner March 8, 2025 12:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@hwbrzzl hwbrzzl closed this Mar 8, 2025
@hwbrzzl hwbrzzl reopened this Mar 8, 2025
@hwbrzzl hwbrzzl merged commit 4d97391 into master Mar 8, 2025
14 of 15 checks passed
@hwbrzzl hwbrzzl deleted the bowen/#358-18 branch March 8, 2025 13:06
almas-x pushed a commit that referenced this pull request Mar 12, 2025
* feat: [#358] Add Select, Delete, Update, Insert methods

* update mod

* fix test

* fix test

* chore: update mocks

* fix test

---------

Co-authored-by: hwbrzzl <24771476+hwbrzzl@users.noreply.github.com>
almas-x pushed a commit that referenced this pull request Mar 18, 2025
* feat: [#358] Add Select, Delete, Update, Insert methods

* update mod

* fix test

* fix test

* chore: update mocks

* fix test

---------

Co-authored-by: hwbrzzl <24771476+hwbrzzl@users.noreply.github.com>
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.

2 participants