RobinBlomberg / kysely-codegen

Generate Kysely type definitions from your database.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generate runtime enums

mariandaniel24 opened this issue · comments

I'm trying to generate postgres types with this package, while it works, I'd like a way to generate constants/enums for PG types. As a side note, this is also the behavior of prisma-kysely.
The main reason is so that I can import the enum into zod, z.nativeEnum(RiskEvaluationStatus).parse(someUserInput), but I'm sure there can be other valid use cases.

So the following PG type:

CREATE TYPE risk_evaluation_status AS ENUM ('OK', 'CAN_USE', 'SHOULD_NOT_BE_USED');

Currently generates:

export type RiskEvaluationStatus = "CAN_USE" | "OK" | "SHOULD_NOT_BE_USED";

Instead, I'd like it to generate:

// either this
export const RiskEvaluationStatus = {
  CAN_USE: 'CAN_USE',
  OK: 'OK',
  SHOULD_NOT_BE_USED: 'SHOULD_NOT_BE_USED'
} as const;
export type RiskEvaluationStatus = (typeof RiskEvaluationStatus)[keyof typeof RiskEvaluationStatus];

// or this
export enum RiskEvaluationStatus {
  CAN_USE = 'CAN_USE',
  OK = 'OK',
  SHOULD_NOT_BE_USED = 'SHOULD_NOT_BE_USED'
}

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar