RobinBlomberg / kysely-codegen

Generate Kysely type definitions from your database.
MIT License
690 stars 62 forks source link

--runtime-enums not working as expected #152

Open avermeil opened 2 months ago

avermeil commented 2 months ago

Hello!

I believe that there is an issue with the --runtime-enums flag.

Given this mysql table definition:

CREATE TABLE `campaign_attributes` (
  `opt_account_id` varchar(30) NOT NULL,
  `id` bigint unsigned NOT NULL,
  `name` varchar(250) DEFAULT NULL,
  `status` enum('ENABLED','PAUSED','REMOVED','ENABLED_NOT_SERVING','UNKNOWN') NOT NULL,
  PRIMARY KEY (`opt_account_id`,`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
/*!50100 PARTITION BY KEY (opt_account_id)
PARTITIONS 100 */;

And this command:

kysely-codegen --runtime-enums --camel-case --dialect mysql --url 'mysql://db/warehouse?user=user&password=password'

I get the output:

export interface CampaignAttributes {
  id: number;
  name: string | null;
  optAccountId: string;
  status: "ENABLED" | "ENABLED_NOT_SERVING" | "PAUSED" | "REMOVED" | "UNKNOWN";
}

This is with kysely-codegen@0.15.0.

Shouldn't the output be using enums instead of strings for the field status?

Thanks for any help :)

Upvote & Fund

Fund with Polar