sqlc
sqlc copied to clipboard
Implement rename_enum option (Fix #2129)
This pull request adds support for renaming Go enum values via a new rename_enum option in the configuration. The changes update the code generation logic to use custom names for enum values if specified, and ensure that enum value renaming is handled consistently across global and local options.
Configuration and code generation enhancements:
- Added a new
RenameEnumfield to theOptionsandGlobalOptionsstructs ininternal/codegen/golang/opts/options.go, allowing users to specify custom names for enum values. [1] [2] - Updated the JSON schema in
internal/config/v_two.jsonto support the newrename_enumconfiguration property. - Modified the
Parsefunction ininternal/codegen/golang/opts/options.goto merge globalRenameEnummappings into local options during parsing.
Enum value naming logic improvements:
- Changed the
EnumValueNamefunction ininternal/codegen/golang/enum.goto accept options and use the custom name fromRenameEnumif available, as well as to respect initialisms. - Updated enum value generation in
internal/codegen/golang/result.goto use the newEnumValueNamelogic, ensuring renamed values are used in generated code.
These changes closes #2129.