Added singleton Put for doobie enums - #467
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #467 +/- ##
==========================================
+ Coverage 85.71% 85.76% +0.05%
==========================================
Files 63 64 +1
Lines 511 513 +2
Branches 34 34
==========================================
+ Hits 438 440 +2
Misses 73 73 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR improves enumeratum-doobie ergonomics by making Doobie Write instances available for singleton enum entries (e.g., FooStatus.Initiated.type), removing the need to manually widen singleton values to the parent enum type when using them in SQL fragments.
Changes:
- Add an implicit singleton
Putinstance forDoobieEnumentries, enablingWritederivation for singleton values. - Add an implicit singleton
Putinstance forDoobieValueEnumentries, enablingWritederivation for singleton values. - Extend existing ScalaTest specs to assert
Write[...]availability for representative singleton enum values.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| enumeratum-doobie/src/main/scala/enumeratum/DoobieEnum.scala | Adds enumSingletonPut to provide Put (and thus Write) for singleton enum entries. |
| enumeratum-doobie/src/main/scala/enumeratum/values/DoobieValueEnum.scala | Adds enumSingletonPut to provide Put (and thus Write) for singleton value-enum entries. |
| enumeratum-doobie/src/test/scala/enumeratum/DoobieEnumSpec.scala | Adds a test that Write can be summoned for a singleton enum entry type. |
| enumeratum-doobie/src/test/scala/enumeratum/values/DoobieValueEnumSpec.scala | Adds tests that Write can be summoned for singleton value-enum entry types (Int/Long/Short examples). |
lloydmeta
left a comment
There was a problem hiding this comment.
LGTM. Will merge when I have time to release as well.
|
Released in 1.9.7 |
At $work we've have a lot of enums like
which are used in fragments with
status = ${FooStatus.Initiated: FooStatus}. We must manually widen the type in order for theWrite[FooStatus]instance to be found.This PR makes
Write-instances available for all singleton values in anenumeratum-doobieEnum. We can now writestatus = ${FooStatus.Initiated}which is a lot cleaner.