Skip to content
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

Support for ENUM? #161

Closed
cakoose opened this issue Nov 6, 2020 · 2 comments
Closed

Support for ENUM? #161

cakoose opened this issue Nov 6, 2020 · 2 comments

Comments

@cakoose
Copy link
Contributor

cakoose commented Nov 6, 2020

Is there a way to use Postgres ENUM fields with Mammoth v1.x?

The v0.10.x docs have something called EnumColumn, but I can't see anything like that in the v1.x codebase.

@martijndeh
Copy link
Contributor

Correct, this is not supported in the main branch right now. I'll get this back in.

As an alternative, you can use a text column but pass in your own type. This does not give you the database safety checks you get when you use a type, but it gives you the same safety checks in your application code. The downside of a postgres type is that you cannot remove a value (you can rename a value though).

The below creates a test column with a specific string union type.

export const test = defineTable({
  id: uuid().primaryKey().notNull().default('gen_random_uuid()'),
  test: text<'foo' | 'bar' | 'baz'>().notNull(),
});

@martijndeh
Copy link
Contributor

martijndeh commented Nov 8, 2020

This is supported again. You can use the enumType(..) data type to configure this. I'll go through mammoth-cli as well to support creating and altering types as well.

export const test = defineTable({
  id: uuid().primaryKey().notNull().default('gen_random_uuid()'),
  test: enumType('my_enum_type', ['A', 'B', 'C'] as const).notNull(),
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants