-
Notifications
You must be signed in to change notification settings - Fork 149
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
Doobe Psql module integration #308
Comments
Hey, that sounds reasonable to me. To double check my understanding: the current issue is that the enum in the doobie module basically only supports going to-and-from strings, but not Postgres custom enum types. Your proposal is to add the ability to support custom enum types by giving the user a way of specifying the enum type when declaring the enum type (in scala land) I think your suggestion makes sense; can give an example of how that would look in actual usage? Just want to double check that it feels right 🙂 |
sure it would be something like: trait DoobieStrictEnum[A <: EnumEntry] { this: Enum[A] =>
def pgEnumTypeName: String
implicit def meta: Meta[A] = pgEnumString(pgEnumTypeName, this.withName(_), _.entryName)
} then user implementation would be like: sealed trait ShirtSize extends EnumEntry
object ShirtSize extends Enum[ShirtSize] with DoobieStrictEnum[ShirtSize] {
//all your case objects here
val pgEnumTypeName: String = "shirt_size"
} the name |
That looks reasonable to me. However, I just realised that we're talking about Postgres enums, and the Doobie integration we have so far, There are a few paths forward:
Quite candidly, at the moment, I don't really have much capacity nor desire to support (3) given the large number of existing modules. What are your thoughts on (1) and (2)? |
Actually I came to the same realization yesterday when I started having a closer look at this 😁 I don't think (2) is that worthwhile unless there was substantially more that could be pulled out into its own package - its really only 2 lines. I think (1) is fine. I'll submit a PR to update the readme. |
Hi guys. Just curious – any progress on this issue? I also faced this issue in my project some time ago and came up with a similar solution eventually. But it would be nice if I could use some common solution instead of our custom one. |
At this point, the issue is to add a section to the readme to document the Doobie + Psql mix in. There are no plans to add a Psql-specific integration, if that's your question. |
Very similar issue to #227 . If you use
DoobieEnum
with postgres enum types, you get errors like:"org.postgresql.util.PSQLException: ERROR: column "shirt" is of type shirtsize but expression is of type character varying"
In order to work with postgres enums in doobie, you need to provide the name of the type you have created. E.g. if you have
CREATE TYPE shirt_size AS ENUM ('small', 'medium', 'large');
, then you need to create a doobiemeta
instance like so:implicit val meta: Meta[ShirtSize] = pgEnumString("shirt_size", withName(_), _.entryName)
.If
enumeratum-doobie
was going to include such an instance for the user, you would probably have to adddef enumTypeName: String
as an implementation detail for the user inDoobieEnum
. Maybe instead a new mixin calledDoobieStrictEnum
could be added that provides this functionality? Happy to work on a PR for this and add a section to the readme, if there is interest for this.The text was updated successfully, but these errors were encountered: