Typing enums
First of all, I still really enjoy using Kysely, great library!
I have the following pattern for
enums
. I create the role
table as an "enum" table (which I got from another help post I was reading earlier) and add it as an foreign key to the teacher
table.
I also have the ROLES enum
to use across my back-end for various purposes
When I define the types for this table I do the following:
This works for typesafety of course, but I'd like for role
to be only values of the ROLES enum
.
Does it make sense to just change it from string
to Role
or am I missing something2 Replies
Just changing
string
to Role
should work perfectlyAlright thanks
I believe I was making it harder then needed to be. I was looking for a way to sync enum values from the database (either with a pgEnum or the enum table from above) with this:
But enum values should not change often so just adding them if it happens to the definition makes more sense