Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1328 +/- ##
=======================================
Coverage 70.07% 70.07%
=======================================
Files 282 282
Lines 16752 16752
=======================================
Hits 11739 11739
Misses 4522 4522
Partials 491 491 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This pull request fixes issue #818 by enhancing the database row scanning capabilities to properly handle JSON columns when using cursors. The implementation introduces a unified approach for handling custom types with Scan methods (including Carbon types) and adds dedicated hooks for JSON deserialization to slices and maps.
Key Changes:
- Replaced the specialized
ToCarbonHookFuncwith a genericToScannerHookFuncthat handles all types implementingScan(any) error, including Carbon types and custom types - Added
ToSliceHookFuncandToMapHookFuncto automatically deserialize JSON strings into Go slices and maps - Refactored
database/gorm/row.goto delegate scanning logic to the centralizeddatabase/db/row.go, eliminating code duplication - Enhanced field name matching to support both snake_case and StudlyCase mappings
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| database/db/row.go | Added new decode hooks (ToScannerHookFunc, ToSliceHookFunc, ToMapHookFunc) for JSON and custom type handling; improved field name matching logic |
| database/gorm/row.go | Simplified by delegating Scan implementation to centralized db.Row logic |
| database/db/row_test.go | Added comprehensive unit tests for new decode hooks covering time, carbon, deleted_at, scanner, and basic type conversions |
| tests/query_test.go | Added integration tests for scanning JSON columns into maps, string slices, int slices, and custom structs with Scan methods |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/gemini summary |
Summary of ChangesThis pull request resolves an issue where the database cursor could not properly scan JSON columns by introducing robust enhancements to the row scanning and decoding mechanisms. It centralizes and extends the decoding logic to seamlessly handle JSON data into Go slices and maps, as well as custom types that implement the Highlights
Changelog
Activity
|
📑 Description
Closes goravel/goravel#818
This pull request significantly enhances the database row scanning and decoding capabilities, especially for handling JSON data and custom types. It introduces new decode hooks for slices, maps, and types implementing the
Scanmethod, and updates the test suite to validate these improvements. Additionally, it simplifies the codebase by delegating scanning logic and updates dependencies.Enhancements to Row Scanning and Decoding:
database/db/row.goto support automatic conversion of JSON strings to Go slices and maps, and to handle types implementing theScan(any) errorinterface (such as custom and Carbon types). This improves flexibility and correctness when scanning database rows into Go structs. [1] [2]snake_caseandStudlyCasemappings, increasing compatibility with various struct field naming conventions.Refactoring and Codebase Simplification:
database/gorm/row.goto delegate theScanmethod to the new, centralized logic indatabase/db/row.go, removing duplicated code and reducing maintenance overhead. [1] [2]Testing Improvements:
tests/query_test.gofor scanning JSON columns intomap[string]any, slices ([]string,[]int), and custom structs, ensuring robust support for a variety of data types and structures.Dependency Updates:
github.com/goravel/frameworkdependency fromv1.15.9tov1.16.5and added a new indirect dependency ongithub.com/urfave/cli/v3in the test module. [1] [2]✅ Checks