fix(gen): apply configured struct tags to generated query structs - #762
Open
ChrisJr404 wants to merge 1 commit into
Open
fix(gen): apply configured struct tags to generated query structs#762ChrisJr404 wants to merge 1 commit into
ChrisJr404 wants to merge 1 commit into
Conversation
Query result structs only ever received a db tag, so tags configured via tags/struct_tag_casing (json and friends) were missing from them even though model structs already honored them. Reuse the same helpers the model template uses so query row fields get the configured tags. Output is unchanged when no tags are set. Closes stephenafamo#602
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The generated struct for a configured query only ever got a
dbtag. Tags set in the config (json and so on) were applied to model structs but not to query result structs, so anyone relying on json output from queries had to add the tags by hand.This reuses the same
generateTags/columnTagNamehelpers the model template already uses, so query row fields now honor thetagsandstruct_tag_casingconfig. When no tags are configured the output is unchanged.Added an offline regression test that generates a query through a stub driver (no database) and checks the row struct carries the json tag. It fails on main and passes with this change.
Closes #602