RobinBlomberg / kysely-codegen

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

Introspecting enum fields #70

Open mkieblesz opened 1 year ago

mkieblesz commented 1 year ago

At the moment kysely-codegen is not introspecting checks in postgres dialect.

Following table:

CREATE TABLE "example" (
    "id" bigserial PRIMARY KEY,
    "status" text CHECK ("status" IN ("public", "restricted", "private")) NOT NULL DEFAULT "restricted",
)

becomes

export interface Example {
  id: Generated<Int8>;
  status: Generated<string>;
}

while it should be

export interface Example {
  id: Generated<Int8>;
  status: Generated<'public' | 'restricted' | 'private'>;
}

I didn't take a look at the codebase yet, so if you could point me to the right direction I could implement that. Thanks!

ps. useful take on ENUMS vs CHECKS https://stackoverflow.com/a/10984951/11060504

Upvote & Fund

Fund with Polar

KenParsons commented 1 year ago

I came here to suggest similar, but specifically because of SQLite and its lack of an enum type or similar. The CHECK approach is basically the only way to get the same behavior, so making this improvement would be a huge boon for SQLite users.