- Notifications
You must be signed in to change notification settings - Fork 955
Description
Version
1.24.0
What happened?
When using mysql
as the engine, the table and column names are normalized to lowercase, losing useful naming conventions from the database. It's a very postgres specific thing that table and column names should be lowercase. But in Mysql this limitation does not exist.
e.g. a column called KapNr
will become Kapnr
in the generated struct. If I then marshal that into a JSON, even with JSON tags in camelCase it will just become kapnr
instead of kapNr
.
We can use the rename
configuration, but then that configuration is ignored for generating the json tag, so it is still only half a workaround.
For context (feel free to skip), to keep my code simple, the way I name my columns in a database, structs and output JSON are usually as similar as possible. The less mapping from 1 format to another, the better. However, now I am forced to put extra mappings in between with custom structs to fix this.
Relevant log output
No response
Database schema
CREATE TABLE `Gruppen` ( `GrVon` varchar(3) NOT NULL, `GrBis` varchar(3) DEFAULT NULL, `KapNr` varchar(2) DEFAULT NULL, `GrTi` varchar(255) DEFAULT NULL, PRIMARY KEY (`GrVon`), KEY `KapNr` (`KapNr`), CONSTRAINT `Gruppen_ibfk_1` FOREIGN KEY (`KapNr`) REFERENCES `Kapitel` (`KapNr`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
SQL queries
No response
Configuration
version: "2" sql: - engine: "mysql" queries: "sql/queries" schema: "sql/schema" gen: go: out: "internal/database" emit_json_tags: true json_tags_case_style: camel rename: kapnr: "KapNr"
Playground URL
https://play.sqlc.dev/p/28279d28759d2a8d64af19286ee73de6c27b7003d0caa821d0e311652cf01a17
What operating system are you using?
Linux
What database engines are you using?
MySQL
What type of code are you generating?
Go