-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sqlc will auto convent BookID to Bookid. It's a bug. #2392
Comments
OK, I see the documentation in https://docs.sqlc.dev/en/stable/reference/config.html#renaming-fields Now I know the algorithm is this.
I will say it is really not a good idea. Because in the real world, not all the table field in database is like There are so many so many so many table field is like Maybe someone will say "It's not a bug. It's a feature." |
In Postgres, table names are normalized to lowercase unless you double quote those columns: So for example CREATE TABLE authors (
-- ...
BookID int
); Is functionally the same as: CREATE TABLE authors (
-- ...
bookid int
); However, if you specify your column with double quotes, you will see that sqlc in fact generates the correct struct name (see my sqlc play link): CREATE TABLE authors (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name text NOT NULL,
bio text,
"BookID" int
); https://play.sqlc.dev/p/c1481d2a3b6ec10a6728b7d99b3c35c4133766e585cbd463736b4108ae21fa13 |
I am using mysql, not Postgres. And it will have sql error if I use |
I also try CREATE TABLE authors1 (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name text NOT NULL,
bio text,
`BookID` int
) and sqlc generate type Author struct {
ID int64
Name string
Bio sql.NullString
Bookid sql.NullInt32
} |
Hope to add the feature to keep the case of mysql field. The reason why I need to keep the case of mysql field, is that I use many auto generated golang code generated by tool. |
@ankisme The section below that explains how to overwrite field names, have you tried that? Working example: https://play.sqlc.dev/p/2f4eef0c6c87569b5a1b531e6a4a37b0849d9d0d26959ec6a89dcfd982c9f47c |
I have not try. Because I fork sqlc and modify some code to support original field name like AaBbCc. Maybe I will try |
Version
1.18.0
What happened?
My sql field is BookID, but sqlc will convert BookID to Bookid.
Maybe many people think that it is not a bug.
But I really think it is a bug.
I like BookID or BookId, and I don't like Bookid at all.
ThisIsAnExample is much more better than Thisisanexample.
AuthorName is much more better than Authorname.
And I could not found any configuration to forbid the auto rename.
Relevant log output
No response
Database schema
No response
SQL queries
No response
Configuration
No response
Playground URL
No response
What operating system are you using?
No response
What database engines are you using?
No response
What type of code are you generating?
No response
The text was updated successfully, but these errors were encountered: