Preserve upper-case when mapping SQL identifiers to Go identifiers
What do you want to change?
It would be great if sqlc could leave upper-case letters as upper-case when mapping SQL identifiers to Go identifiers.
The existing behavior works pretty well for all-lowercase SQL identifiers using underscores:
(SQL) (Go)
request_id => RequestID
http_id => HttpID
artwork_key => ArtworkKey
But some databases use camel-case naming convention. Currently, sqlc changes upper-case letters to lower-case, producing:
(SQL) (Go)
RequestID => Requestid
HTTPID => Httpid
ArtworkKey => Artworkkey
My proposal: leave upper-case letters as upper-case, and otherwise keep the existing behavior. This wouldn't affect anyone who uses all-lowercase SQL names, and it would produce nicer results for mixed-case SQL names:
(SQL) (Go)
RequestID => RequestID
HTTPID => HTTPID
ArtworkKey => ArtworkKey
If this is acceptable, I'd be happy to submit a patch.
How does it sound?
What database engines need to be changed?
No response
What programming language backends need to be changed?
Go
I think the desired behaviour should be to only uppercase the first character and let the reset of the characters preserve their original case.
If that's the case, I have fixed it by replacing strings.Title with code that only uppercases the first character.
It's good IMO for sqlc to uppercase letters that follow underscores, as it currently does. The existing call to strings.Title uppercases the first letter and preserves the case of the rest. The problem as I see it is that the entire name is lowercased at some point before StructName is even called.
(BTW, this also means that the rename map in sqlc.json has to use all-lowercase keys. Which is kind of surprising and arguably a bug?)
strings.Title lowercases the rest of the characters except the first one, and that's the problem I think?
The strings.Title function doesn’t lowercase the other letters. It only uppercases letters that follow word boundaries. It leaves the rest as they were.
https://go.dev/play/p/LfFvIXQqXsc
Oh I stand corrected here! My source of information about strings.Title was wrong.
I tried everything to find where the field names are being lowercased but hard luck..