fix: [#660] WhereBetween, etc. method can't support string correctly#1037
Merged
fix: [#660] WhereBetween, etc. method can't support string correctly#1037
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances SQL safety by parameterizing range queries, refines the test suite to focus on PostgreSQL, and adds date-range tests for the new behavior.
- Updated
WhereBetween,WhereNotBetween,OrWhereBetween, andOrWhereNotBetweento use?placeholders. - Commented out MySQL/SQLServer/SQLite in the test builder and moved table creation into
SetupTest. - Introduced date-based filtering tests using
carbon.Now()andtime.Sleep.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tests/query_test.go | Moved table setup to SetupTest, added date-range test cases |
| tests/query.go | Disabled non-Postgres drivers in All() builder |
| database/gorm/query.go | Parameterized BETWEEN/NOT BETWEEN methods |
Comments suppressed due to low confidence (1)
tests/query_test.go:3425
- [nitpick] The user name and variable indicate a BETWEEN scenario within the
OrWhereNotBetweentest; consider renaming to reflect the 'not_between' context for clarity.
user3 := User{Name: "or_where_between_user_3", Avatar: "or_where_between_avatar_3"}
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1037 +/- ##
==========================================
- Coverage 70.48% 70.45% -0.04%
==========================================
Files 176 176
Lines 12339 12339
==========================================
- Hits 8697 8693 -4
- Misses 3261 3264 +3
- Partials 381 382 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📑 Description
Closes goravel/goravel#660
This pull request includes updates to the
Querymethods in thedatabase/gorm/query.gofile to improve SQL query parameterization, as well as changes to the test suite intests/query.goandtests/query_test.goto adjust test behavior and add new test cases for date-based filtering. Below are the most important changes grouped by theme:Query Parameterization Improvements:
WhereBetween,WhereNotBetween,OrWhereBetween, andOrWhereNotBetweenmethods indatabase/gorm/query.goto use parameterized queries with placeholders (?) instead of directly embedding values in the SQL string. This change enhances security by preventing SQL injection and improves query performance.Test Suite Adjustments:
tests/query.go, leaving only PostgreSQL active. This change simplifies the test environment, likely for debugging or temporary exclusion of unsupported databases.SetupSuitemethod to theSetupTestmethod intests/query_test.go. This ensures a clean test environment for each test case by recreating tables before each test.New Test Cases for Date-Based Filtering:
tests/query_test.goforWhereBetween,WhereNotBetween,OrWhereBetween, andOrWhereNotBetweenmethods to validate filtering based on thecreated_attimestamp. These tests ensure that the methods work correctly with date ranges. [1] [2] [3] [4]Minor Test Enhancements:
carbon.Now()timestamp in several test cases to provide dynamic date-based filtering, improving the robustness and relevance of the tests. [1] [2]✅ Checks