Skip to content

templates/go: disambiguate fields from digit-prefixed SQL columns#434

Open
rosensama wants to merge 1 commit into
xo:mainfrom
rosensama:fix/digit-prefix-column-names
Open

templates/go: disambiguate fields from digit-prefixed SQL columns#434
rosensama wants to merge 1 commit into
xo:mainfrom
rosensama:fix/digit-prefix-column-names

Conversation

@rosensama
Copy link
Copy Markdown

Summary

  • Columns like 1X, 2X, 3X all collapse to a single Go field X because snaker.ForceCamelIdentifier strips leading digits — generating structs with duplicate fields that fail to compile.
  • Fix: when a SQL column name starts with a digit, append _<sanitized original> to the generated GoName (e.g. 1XX_1X, 2XX_2X).
  • Sanitization of the appended original matches the current snaker identifier rune class (Unicode letters, digits, underscore), which in turn matches the Go language spec.

Fixes #433.

Tested against an MSSQL repro of the issue with a local build.

🤖 Generated with Claude Code

snaker.ForceCamelIdentifier strips leading digits, so columns "1X", "2X",
"3X" all collapse to a single Go field named "X" — producing structs with
duplicate fields that won't compile.

When a column name starts with a digit, append "_<sanitized original>" to
the generated GoName ("1X" -> "X_1X"). Sanitization matches the current
snaker identifier rune class (Unicode letters, digits, underscore), which
in turn matches the Go language spec.

Fixes xo#433.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

Invalid fields generated from table with multiple columns whose name beings with a number and ends in same string

1 participant