RobinBlomberg / kysely-codegen

Generate Kysely type definitions from your database.
MIT License
819 stars 73 forks source link

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

Closed lintellme99 closed 3 months ago

lintellme99 commented 3 months 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 3 months ago

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

lintellme99 commented 3 months ago

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

Thank you so much!