Skip to content
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

MySQL table and column names should not be normalized to lowercase #3089

Open
c00 opened this issue Dec 31, 2023 · 2 comments
Open

MySQL table and column names should not be normalized to lowercase #3089

c00 opened this issue Dec 31, 2023 · 2 comments
Labels
bug Something isn't working triage New issues that hasn't been reviewed

Comments

@c00
Copy link

c00 commented Dec 31, 2023

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

@c00 c00 added bug Something isn't working triage New issues that hasn't been reviewed labels Dec 31, 2023
@a-berahman
Copy link

Any updates on this issue?

Luke-zhang-04 added a commit to Quackers2446/restaurant-flow that referenced this issue Jul 8, 2024
@a-berahman
Copy link

PR to fix this issue: #3513

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage New issues that hasn't been reviewed
Projects
None yet
Development

No branches or pull requests

2 participants