Skip to content

fix: [#660] WhereBetween, etc. method can't support string correctly#1037

Merged
hwbrzzl merged 2 commits intomasterfrom
bowen/#660-1
May 18, 2025
Merged

fix: [#660] WhereBetween, etc. method can't support string correctly#1037
hwbrzzl merged 2 commits intomasterfrom
bowen/#660-1

Conversation

@hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented May 18, 2025

📑 Description

Closes goravel/goravel#660

This pull request includes updates to the Query methods in the database/gorm/query.go file to improve SQL query parameterization, as well as changes to the test suite in tests/query.go and tests/query_test.go to adjust test behavior and add new test cases for date-based filtering. Below are the most important changes grouped by theme:

Query Parameterization Improvements:

  • Updated the WhereBetween, WhereNotBetween, OrWhereBetween, and OrWhereNotBetween methods in database/gorm/query.go to 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:

  • Commented out the initialization of MySQL, SQL Server, and SQLite test queries in tests/query.go, leaving only PostgreSQL active. This change simplifies the test environment, likely for debugging or temporary exclusion of unsupported databases.
  • Moved the creation of test tables from the SetupSuite method to the SetupTest method in tests/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:

  • Added test cases in tests/query_test.go for WhereBetween, WhereNotBetween, OrWhereBetween, and OrWhereNotBetween methods to validate filtering based on the created_at timestamp. These tests ensure that the methods work correctly with date ranges. [1] [2] [3] [4]

Minor Test Enhancements:

  • Introduced a carbon.Now() timestamp in several test cases to provide dynamic date-based filtering, improving the robustness and relevance of the tests. [1] [2]

✅ Checks

  • Added test cases for my code

Copilot AI review requested due to automatic review settings May 18, 2025 11:05
@hwbrzzl hwbrzzl requested a review from a team as a code owner May 18, 2025 11:05
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.

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, and OrWhereNotBetween to 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() and time.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 OrWhereNotBetween test; 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
Copy link

codecov bot commented May 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.45%. Comparing base (c86a9f1) to head (a6ce065).
Report is 1 commits behind head on master.

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.
📢 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 merged commit e30b6e5 into master May 18, 2025
13 of 14 checks passed
@hwbrzzl hwbrzzl deleted the bowen/#660-1 branch May 18, 2025 13:30
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.

WhereBetween, etc. method can't support string correctly

2 participants