Skip to content

fix(gen): apply configured struct tags to generated query structs - #762

Open
ChrisJr404 wants to merge 1 commit into
stephenafamo:mainfrom
ChrisJr404:query-struct-tags
Open

fix(gen): apply configured struct tags to generated query structs#762
ChrisJr404 wants to merge 1 commit into
stephenafamo:mainfrom
ChrisJr404:query-struct-tags

Conversation

@ChrisJr404

Copy link
Copy Markdown

The generated struct for a configured query only ever got a db tag. 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/columnTagName helpers the model template already uses, so query row fields now honor the tags and struct_tag_casing config. 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

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

json and struct_tag_casing

1 participant