-
Notifications
You must be signed in to change notification settings - Fork 109
fix: [#818] Cursor cannot scan json column #1327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v1.16.x #1327 +/- ##
==========================================
Coverage ? 67.97%
==========================================
Files ? 216
Lines ? 11613
Branches ? 0
==========================================
Hits ? 7894
Misses ? 3339
Partials ? 380 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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 pull request enhances the database row scanning functionality to properly handle JSON columns and custom types. It introduces new decode hooks for automatic JSON-to-Go conversions and consolidates scanning logic in a centralized location, while adding comprehensive test coverage for the new capabilities.
Key Changes:
- Added three new decode hooks (ToScannerHookFunc, ToSliceHookFunc, ToMapHookFunc) to handle JSON string conversions to slices, maps, and types with custom Scan methods
- Improved field name matching to support snake_case database columns mapping to Go struct fields
- Refactored
database/gorm/row.goto delegate to centralized scanning logic indatabase/db/row.go
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| database/db/row.go | Added new decode hooks for JSON parsing (ToScannerHookFunc, ToSliceHookFunc, ToMapHookFunc) and enhanced field name matching logic to support snake_case mappings |
| database/db/row_test.go | New comprehensive test suite covering string conversions, time conversions, Carbon type conversions, DeletedAt conversions, and JSON scanning scenarios |
| database/gorm/row.go | Refactored to delegate Scan implementation to database/db/row.go, removing duplicate code |
| tests/query_test.go | Added integration tests for cursor scanning with JSON columns into maps, string slices, int slices, and custom structs with Scan methods |
| tests/query.go | Modified test configuration to only run SQLite tests (PostgreSQL, MySQL, and SQL Server tests commented out) |
| tests/go.mod | Updated framework dependency from v1.15.9 to v1.16.5 |
| tests/go.sum | Added new indirect dependency github.com/urfave/cli/v3 v3.3.8 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📑 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