-
Notifications
You must be signed in to change notification settings - Fork 108
Add support for custom types #1998
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
base: master
Are you sure you want to change the base?
Conversation
summaryInferred base version: v3.125.0 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1998 +/- ##
==========================================
- Coverage 74.18% 74.12% -0.06%
==========================================
Files 397 397
Lines 34737 34832 +95
==========================================
+ Hits 25768 25820 +52
- Misses 7850 7878 +28
- Partials 1119 1134 +15
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Replace reflect.TypeOf with reflect.TypeFor for type-safe type retrieval - Consolidate basic type handling into main switch statement - Remove redundant type alias conversion logic - Use rv.Kind() directly instead of separate kind variable
…rrectly - Add basic type handling via reflect.Kind() in toType function - Handle byte slices ([]byte and type aliases) as Bytes type instead of List - Fix test failures for custom types
- Extract basic type handling to basicKindToType helper function - Extract slice/array handling to sliceArrayToType helper function - Extract map handling to mapToType helper function - Extract struct handling to structToType helper function - Extract concrete type handling to concreteTypeToType helper function - Reduce cyclomatic complexity from 43 to acceptable level
- Extract reflect.Kind() handling logic to reflectKindToType function - Keep original toType structure with concrete type switch - Only new reflect-based functionality is extracted
- Keep toType in its original position after asSQLNullValue - Place reflectKindToType immediately after toType - This minimizes diff size by not moving the main toType function
- Modify test cases in params_test.go to create pointers from local variables instead of passing them directly to functions. - This change improves clarity and avoids potential issues with variable lifetimes in the tests.
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 PR adds support for custom types (type aliases) derived from primitive types in the database/sql driver's parameter binding functionality. The implementation refactors the type handling code to use reflection more efficiently and consolidates basic type handling logic.
- Refactored type detection to support custom type aliases by using reflection-based kind checking
- Consolidated basic type handling into the main switch statement using
reflect.Valuemethods - Added comprehensive test coverage for custom type aliases across all primitive types
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/bind/params.go | Refactored toType() to extract reflection-based type detection into reflectKindToType(), and updated toValue() to handle custom types using reflection kind checking |
| internal/bind/params_test.go | Added custom type definitions and comprehensive test cases covering all primitive type aliases including pointer and nil variants |
| CHANGELOG.md | Added changelog entry documenting the new feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
- Introduced derived types for various SQL data types to improve test coverage. - Added test cases for int8, int16, int32, int64, uint8, uint16, uint32, uint64, float32, float64, bool, string, and byte slices. - Each type includes both direct and derived type tests to ensure proper scanning behavior.
- Add castToDerivedType function to handle type aliases via reflection - Support derived types for int32, uint64, float64, string, bool, bytes, and datetime - Add integration test TestQueryDerivedTypesScan for QueryService - Improve documentation with examples and limitations - Unify datetimeValue derived type handling with castToDerivedType - Optimize reflection calls in castToDerivedType
🌋 SLO Test ResultsStatus: 🔴 7 workloads tested • 1 workloads failed
Generated by ydb-slo-action |
Pull request type
Please check the type of change your PR introduces:
What is the current behavior?
Custom types (type aliases) are not supported in parameter binding. Type handling code uses
reflect.TypeOf()and has redundant type alias conversion logic.Issue Number: N/A
What is the new behavior?
toValue()functionreflect.TypeOf()withreflect.TypeFor[T]()for type-safe type retrievalrv.Kind()directlyOther information