Skip to content

Added singleton Put for doobie enums - #467

Merged
lloydmeta merged 1 commit into
lloydmeta:masterfrom
felix-hedenstrom:singleton-write-doobie
Mar 28, 2026
Merged

Added singleton Put for doobie enums#467
lloydmeta merged 1 commit into
lloydmeta:masterfrom
felix-hedenstrom:singleton-write-doobie

Conversation

@felix-hedenstrom

@felix-hedenstrom felix-hedenstrom commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

At $work we've have a lot of enums like

sealed trait FooStatus extends EnumEntry.UpperSnakecase

object FooStatus extends enumeratum.Enum[FooStatus] with DoobieEnum[FooStatus]:
  val values = findValues

  case object Initiated        extends FooStatus
  case object Completed        extends FooStatus

which are used in fragments with status = ${FooStatus.Initiated: FooStatus}. We must manually widen the type in order for the Write[FooStatus] instance to be found.

This PR makes Write-instances available for all singleton values in an enumeratum-doobie Enum. We can now write
status = ${FooStatus.Initiated} which is a lot cleaner.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.76%. Comparing base (7948eb5) to head (2d77b48).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Put instance for DoobieEnum entries, enabling Write derivation for singleton values.
  • Add an implicit singleton Put instance for DoobieValueEnum entries, enabling Write derivation 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 lloydmeta left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Will merge when I have time to release as well.

@lloydmeta
lloydmeta merged commit 7ffc70a into lloydmeta:master Mar 28, 2026
7 checks passed
@lloydmeta

Copy link
Copy Markdown
Owner

Released in 1.9.7

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

Successfully merging this pull request may close these issues.

4 participants