-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enum type #112
Comments
Well, you can create anything with raw SQL using the No enum support has been added yet to the schema builder because all database engines have different implementation for enums. Also people mean different things when they talk about enums. On postgres there's a way to create new enum types and use those as types for columns. AFAIK no other engine has something like that. Knex creates a check constraint for enums by default on postgres. Kysely doesn't have an abstraction layer on top of SQL. Therefore there's never going to be an API like There are already methods for creating check constraints, but you need to write the check code using raw sql. What kind of support would you like see in kysely? And what do you mean by enum types? |
I can add a |
On mysql enums are simple: .addColumn('some_col', sql`enum('a', 'b', 'c', 'd', 'e')`) You can even create a helper like this: function enum(...args: string[]) {
return sql`enum(${sql.join(args.map(sql.literal))})`
}
.addColumn('some_col', enum('a', 'b', 'c', 'd', 'e')) |
@roitman-g Any thoughts? |
For postgres you can do: await db.schema
.createType("status")
.asEnum(["failed", "success"])
.execute(); and then reference the status type: .addColumn("status", sql`status`) |
When I do this, it throws a ts error saying that is not assignable to DataTypeExpression |
@vladstavarache fixed your example with sql template tag usage in @bhgames check the example again. |
the example above worked for me! I'm using postgres I created this pr to add enum in doc: #504 |
@igalklebanov , For me the following solution worked, when I want to use different name(UserStatus) for type.
and then reference the UserStatus type:
|
@anoopsimelabs @vladshcherbin how would you do migrations if you need to change the type? It doesn't seem like db.schema has any way to change the type. Is it better to just do raw SQL for this? |
I wonder if it is possible to create enum types with Kysely? I have not found anything in docs
The text was updated successfully, but these errors were encountered: