sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Implement rename_enum option (Fix #2129)

Open heyvito opened this issue 1 month ago • 0 comments

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 RenameEnum field to the Options and GlobalOptions structs in internal/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.json to support the new rename_enum configuration property.
  • Modified the Parse function in internal/codegen/golang/opts/options.go to merge global RenameEnum mappings into local options during parsing.

Enum value naming logic improvements:

  • Changed the EnumValueName function in internal/codegen/golang/enum.go to accept options and use the custom name from RenameEnum if available, as well as to respect initialisms.
  • Updated enum value generation in internal/codegen/golang/result.go to use the new EnumValueName logic, ensuring renamed values are used in generated code.

These changes closes #2129.

heyvito avatar Nov 06 '25 01:11 heyvito