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

UUID encoder in quill-async not compatible with mysql #594

Closed
zifeo opened this issue Oct 19, 2016 · 1 comment
Closed

UUID encoder in quill-async not compatible with mysql #594

zifeo opened this issue Oct 19, 2016 · 1 comment
Labels

Comments

@zifeo
Copy link
Contributor

zifeo commented Oct 19, 2016

Version: 0.10.1-SNAPSHOT
Module: quill-async-mysql
Database: mariadb
#585 follow up.

Expected behavior

Everything encode/decode without the need of defining encoder/decoder.

Actual behavior

io.netty.handler.codec.EncoderException: scala.MatchError: 9cad8ea5-41f5-4ffb-a35d-ecdba68c2eed (of class java.util.UUID) at runtime.

Steps to reproduce the behavior

val db = new MysqlAsyncContext[SnakeCase]("mysql")
import db._

// This works
//implicit val decoderUUID = MappedEncoding[String, AddressId](x => AddressId(UUID.fromString(x)))
//implicit val encoderUUID = MappedEncoding[AddressId, String](_.value.toString)

// This does not work
implicit val decoderUUID = MappedEncoding[String, UUID](UUID.fromString)
implicit val encoderUUID = MappedEncoding[UUID, String](_.toString)

case class AddressId(value: UUID) extends AnyVal
case class Address(id: AddressId)

val addr = AddressId(UUID.randomUUID())
val res = run {
  query[Address].filter(_.id == lift(addr))
}
Await.result(res, Duration.Inf)

Workaround

@getquill/maintainers

@fwbrasil fwbrasil added the bug label Nov 1, 2016
@zifeo
Copy link
Contributor Author

zifeo commented Dec 12, 2016

Note that the workaround is not working anymore in 1.0.1. The async SQL context needs to redefine the encoder/decoder pair depending on your underlying MYSQL type in order to work:

  override implicit val uuidDecoder: Decoder[UUID] =
    AsyncDecoder(SqlTypes.CHAR)(new BaseDecoder[UUID] {
      def apply(index: Index, row: ResultRow): UUID = row(index) match {
        case value: String => UUID.fromString(value)
      }
    })

  override implicit val uuidEncoder: Encoder[UUID] =
    AsyncEncoder[UUID](SqlTypes.CHAR)(new BaseEncoder[UUID] {
      def apply(index: Index, value: UUID, row: PrepareRow): PrepareRow =
        row :+ value.toString
    })

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

No branches or pull requests

2 participants