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

Use optional StringEnumEntry field in case class with Quill in Scala #256

Open
saeedzr opened this issue Oct 25, 2019 · 1 comment
Open

Comments

@saeedzr
Copy link

saeedzr commented Oct 25, 2019

We're using enumeratum successfully when dealing with enum values, both with Circe and with Quill. We define something like this:

sealed abstract class TopicType(val value: String) extends StringEnumEntry
  object TopicType extends StringEnum[TopicType] with StringCirceEnum[TopicType] with StringQuillEnum[TopicType] {
    object Info extends TopicType("info")
    object Warning extends TopicType("warning")

    val values: immutable.IndexedSeq[TopicType] = findValues
  }

  // case class representing our MySQL payload table 
  case class Payload(id: String, topic: TopicType)

and use Payload when decoding / encoding mysql and json using Quill and Circe. With Quill and MySQL this works fine with the following table:

create table payload(
    id varchar(36) not null primary key,
    topic_type enum ('info', 'warning')  not null
)

However, I cannot for the life of me figure out how to make this work when using optional fields for our enumeratum type.

We want to be able to use the payload class like this:

   case class Payload(id: String, topic: Option[TopicType])

When trying to use an optional topic and read from our database using Quill with :

...
run {
   query[Payload].filter(payload => payload.id == lift(someId))
}

we get:

java.util.NoSuchElementException: null is not a member of ValueEnum (warning, info) (ValueEnum.scala:58)

Same thing happens if I do a leftJoin to a table that holds an Enum in it, e.g.:

case class Payload(id: String)
case class PayloadData(payloadId: String, topic: TopicType)
run {
        query[Payload]
          .leftJoin(query[PayloadData])
          .on((p, pd) => p.id == pd.payloadId)
      }

Could it be that we need to specify some custom decoder / encoder to handle options / null values?

@lloydmeta
Copy link
Owner

Hmm, I'm honestly not too sure about this one because I haven't used Quill with this lib myself. Can you try seeing if someone on the Quill side knows?

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