sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
13.45k stars 803 forks source link

Edge case in model name of generated code #3029

Closed SebastienMelki closed 11 months ago

SebastienMelki commented 11 months ago

Version

1.24.0

What happened?

(This seems to be happen only with this specific table name)

I have a table called 'raw_bonus' but the generate struct has the name 'RawBonu'. I've attached a screenshot of my sqlc config.

image

image

image

Relevant log output

No response

Database schema

CREATE TABLE raw_bonus
(
    `raw_bonus_id`       int(11)     NOT NULL AUTO_INCREMENT,
    `file_id`            int(11)     NOT NULL,
    `start_date_time`    datetime    NOT NULL,
    `end_date_time`      datetime    NOT NULL,
    `uri_id`             varchar(20) NOT NULL,
    `source_url`         varchar(255)         DEFAULT NULL,
    `content_check_sum`  varchar(255)         DEFAULT NULL,
    `is_copy_protection` tinyint(1)  NOT NULL DEFAULT '0',
    `bonus_category`     varchar(255)         DEFAULT NULL,
    `bonus_material`     tinyint(1)  NOT NULL DEFAULT '0',
    `bonus_scope`        varchar(255)         DEFAULT NULL,
    `created_on`         timestamp   NULL     DEFAULT CURRENT_TIMESTAMP,
    `updated_on`         timestamp   NULL     DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`raw_bonus_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4

SQL queries

No response

Configuration

- path: "db/dbmodels/osn_ingest"
    name: "osn_ingestdb"
    engine: "mysql"
    schema: "db/dbschemas/osn_ingest"
    queries: "db/queries/osn_ingest"
    emit_db_tags: true
    emit_exported_queries: true

Playground URL

No response

What operating system are you using?

Linux

What database engines are you using?

MySQL

What type of code are you generating?

Go

andrewmbenton commented 11 months ago

De-pluralization is hard. You should be able to "fix" this with a rename though: https://docs.sqlc.dev/en/latest/howto/rename.html#tables