Skip to content

Conversation

@hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Dec 30, 2025

📑 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 Scan method, 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:

  • Added new decode hooks in database/db/row.go to support automatic conversion of JSON strings to Go slices and maps, and to handle types implementing the Scan(any) error interface (such as custom and Carbon types). This improves flexibility and correctness when scanning database rows into Go structs. [1] [2]
  • Improved field name matching logic in the decoder to support both snake_case and StudlyCase mappings, increasing compatibility with various struct field naming conventions.

Refactoring and Codebase Simplification:

  • Refactored database/gorm/row.go to delegate the Scan method to the new, centralized logic in database/db/row.go, removing duplicated code and reducing maintenance overhead. [1] [2]

Testing Improvements:

  • Added comprehensive tests in tests/query_test.go for scanning JSON columns into map[string]any, slices ([]string, []int), and custom structs, ensuring robust support for a variety of data types and structures.
  • Updated the test query builder to only enable SQLite tests, likely for focused or faster testing.

Dependency Updates:

  • Upgraded the github.com/goravel/framework dependency from v1.15.9 to v1.16.5 and added a new indirect dependency on github.com/urfave/cli/v3 in the test module. [1] [2]

✅ Checks

  • Added test cases for my code

@hwbrzzl hwbrzzl requested a review from a team as a code owner December 30, 2025 02:54
Copilot AI review requested due to automatic review settings December 30, 2025 02:54
@codecov
Copy link

codecov bot commented Dec 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (v1.16.x@7eb482e). Learn more about missing BASE report.

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.
📢 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.

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 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.go to delegate to centralized scanning logic in database/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.

@hwbrzzl hwbrzzl merged commit 26f98ec into v1.16.x Dec 30, 2025
17 checks passed
@hwbrzzl hwbrzzl deleted the bowen/#818 branch December 30, 2025 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants