feat: [#358] Implement ToSql, ToRawSql methods#934
Merged
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #934 +/- ##
=======================================
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. |
Contributor
There was a problem hiding this comment.
PR Overview
This PR implements the ToSql and ToRawSql methods for database query generation and updates various mock, query, logger, and DB functionalities to support the new SQL generation interfaces.
- Added ToSql/ToRawSql methods to the Query and ToSql types.
- Updated the mocks (e.g. ToSql, Query, Driver) and error messages for consistency.
- Refactored logger and DB provider methods to use the updated logger interface (Infof, Warningf, Errorf, Panicf).
Reviewed Changes
| File | Description |
|---|---|
| mocks/database/db/ToSql.go | New autogenerated mock methods for ToSql and related signatures. |
| database/db/to_sql.go | Implementation of ToSql methods and adjusted error handling. |
| database/db/query.go | Introduced ToSql and ToRawSql methods and modified Insert behavior. |
| database/logger/logger.go | Renamed logging methods to Infof/Warningf/Errorf/Panicf and added WithContext usage. |
| contracts/database/db/db.go | Updated the Query interface documentation for ToSql/ToRawSql. |
| errors/list.go | Added new error messages for SQL generation failures and empty data. |
| mocks/database/driver/Driver.go | Renamed parameters in Explain methods for consistency. |
| database/db/db.go | Updated DB construction to use the new logger interface. |
| contracts/database/driver/driver.go | Updated the Explain method signature to reflect renamed parameters. |
| tests/query.go | Updated test dependencies to use the new logger implementation. |
| database/service_provider.go | Adjusted DB build process to use the new logger. |
Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (3)
mocks/database/driver/Driver.go:192
- The parameter name 'vars' has been updated to 'args' to match the driver interface; please verify that all related mock methods consistently use 'args' in both definition and invocation.
r0 = rf(_a0, vars...)
database/db/query.go:271
- This change alters the behavior of Insert by returning an error (DatabaseDataIsEmpty) instead of a Result with zero rows; please confirm that downstream code correctly handles a nil result when data is empty.
if len(mapData) == 0 { return nil, errors.DatabaseDataIsEmpty }
database/logger/logger.go:52
- The logger methods have been refactored to use WithContext(ctx) prior to logging; please ensure that all underlying logger implementations support this context propagation without affecting log formatting.
r.log.WithContext(ctx).Infof(msg, data...)
almas-x
pushed a commit
that referenced
this pull request
Mar 12, 2025
almas-x
pushed a commit
that referenced
this pull request
Mar 18, 2025
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
goravel/goravel#358
@coderabbitai summary
✅ Checks