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

Update codec for resolve decoding error between mysql bit(1) and `s… #308

Merged
merged 1 commit into from
Apr 1, 2016

Conversation

ikhoon
Copy link

@ikhoon ikhoon commented Mar 30, 2016

Fixes Mysql BIT(1) to scala Boolean decoding Error.

Problem

Entity

case class Items(id:Int, brandId: Int, isValid: Boolean)

Table

CREATE TABLE items(`id` int(11),  `brand_id` int(11), `is_valid` bit(1) DEFAULT b'1');

Error

java.lang.IllegalStateException: Value 'RawValue(16,63,true,[B@64697949)' can't be decoded to 'boolean'

    at io.getquill.util.Messages$.fail(Messages.scala:8)
    at io.getquill.sources.finagle.mysql.FinagleMysqlDecoders$$anon$1$$anonfun$apply$1.apply(FinagleMysqlDecoders.scala:34)
    at io.getquill.sources.finagle.mysql.FinagleMysqlDecoders$$anon$1$$anonfun$apply$1.apply(FinagleMysqlDecoders.scala:34)
    at scala.Option.getOrElse(Option.scala:121)
    at io.getquill.sources.finagle.mysql.FinagleMysqlDecoders$$anon$1.apply(FinagleMysqlDecoders.scala:34)
    at io.getquill.sources.finagle.mysql.FinagleMysqlDecoders$$anon$1.apply(FinagleMysqlDecoders.scala:31)

Custom Decoder not working on predefined types

implicit val bitToBooleanDecoder = db.decoder[Boolean] {
  case ByteValue(byte) => byte == (1: Byte)
  case v: RawValue => v.bytes.head == (1 : Byte)
}
val q = quote { (id: Int) =>
  query[Items].filter(i => i.id == id).take(1)
}
db.run(q)(id).map(_.headOption)
// Error:(29, 11) Source doesn't know how to decode 'i.isValid: Boolean'
//    db.run(q)(id).map(_.headOption)
//          ^

Solution

Add RawValue into a Decoder[Boolean]

Notes

Checklist

  • Unit test all changes
  • Update README.md if applicable
  • Add [WIP] to the pull request title if it's work in progress
  • Squash commits that aren't meaningful changes
  • Run sbt scalariformFormat test:scalariformFormat to make sure that the source files are formatted

@getquill/maintainers

@fwbrasil
Copy link
Collaborator

@ikhoon Thank you for the contribution! Could you check why the ci test is failing? https://travis-ci.org/getquill/quill/builds/119487063#L5926

If you need help to setup your local environment, CONTRIBUTION.md has some information.

@ikhoon
Copy link
Author

ikhoon commented Mar 31, 2016

@fwbrasil Sorry for the ci test failing.
I should have checked CONTRIBUTION.md.
After setting local development env & fix the issue.
Thanks!

…cala Bealean`

cause by `java.lang.IllegalStateException: Value 'RawValue(16,63,true,[B@64697949)' can't be decoded to 'boolean'`
@fwbrasil
Copy link
Collaborator

@ikhoon no worries, thanks again for the contribution! 👍 LGTM

@jilen
Copy link
Collaborator

jilen commented Apr 1, 2016

👍

Approved with PullApprove

@fwbrasil fwbrasil merged commit 9df0cb9 into zio:master Apr 1, 2016
@karellen-kim
Copy link
Contributor

Thanks for the approval!! 😄

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