RobinBlomberg / kysely-codegen

Generate Kysely type definitions from your database.
MIT License
773 stars 69 forks source link

How to generate `enum` as `enum`? #182

Closed lintellme99 closed 1 month ago

lintellme99 commented 1 month ago

All my enums in PostgreSQL are generated into type

For example, PostgreSQL:

CREATE TYPE "app_status" AS ENUM (
  'running',
  'not_started',
  'down'
);

Becomes:

export type AppStatuses =
  | 'running'
  | 'not_started'
  | 'down'

After codegen

Is it possible to generate enum as enum? For example:

export enum AppStatuses {
  RUNNING = 'running',
  NOT_STARTED = 'not_started',
  DOWN = 'down'
} 

I want to use it as a:

if (app_status === AppStatuses.DOWN) {
  ...
}

Upvote & Fund

Fund with Polar

RobinBlomberg commented 1 month ago

Hello! You can use the --runtime-enums to generate them. ✨

lintellme99 commented 1 month ago

Thank you so much! I've dig a little deeper and found the solution, but you were literally faster

Thank you so much!