feat: add fallback field mapping for domain struct params#7
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces several fallback strategies for mapping struct fields between the domain and database layers, which is a valuable enhancement for handling inconsistencies in sqlc's generated code. The implementation adds name-based (exact, case-insensitive, snake_case) and position-based matching. I've found a potential issue in the mapping logic where a single source field could be mapped to multiple target fields, and I've provided a suggestion to ensure a one-to-one mapping.
This adds multiple fallback strategies to map source struct fields to target struct fields when field names differ between the wrapper API and the database adapter. The strategies include: exact match, case-insensitive match, snake_case match, and position-based match when structs have the same field count. This is needed because sqlc generates different field names for unnamed query parameters (e.g., LIMIT ? generates 'Limit' instead of 'BatchSize'). The fix enables the generator to correctly map all parameters regardless of naming differences.
The mapping process now tracks available source fields to prevent one source field from being mapped to multiple target fields. After a field is matched, it's removed from the available pool. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7 +/- ##
==========================================
+ Coverage 26.43% 29.21% +2.77%
==========================================
Files 6 6
Lines 643 688 +45
==========================================
+ Hits 170 201 +31
- Misses 468 476 +8
- Partials 5 11 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
fae6af3 to
8beb086
Compare
This adds multiple fallback strategies to map source struct fields to target struct
fields when field names differ between the wrapper API and the database adapter.
The strategies include: exact match, case-insensitive match, snake_case match,
and position-based match when structs have the same field count.
This is needed because sqlc generates different field names for unnamed query
parameters (e.g., LIMIT ? generates 'Limit' instead of 'BatchSize'). The fix enables
the generator to correctly map all parameters regardless of naming differences.