Forked from bancek/patchScalikejdbcStringBinder.scala
Created
November 30, 2017 13:51
-
-
Save xuwei-k/286024112ffff511fc758cdc3cf8d208 to your computer and use it in GitHub Desktop.
Monkey patch scalikejdbc String binder to support UTF8 for MySQL VARBINARY columns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalikejdbc._ | |
package object models { | |
val stringUTF8: Binders[String] = Binders((rs, index) => new String(rs.getBytes(index), "UTF-8"))((rs, label) => new String(rs.getBytes(label), "UTF-8"))(v => (ps, idx) => ps.setBytes(idx, v.getBytes("UTF-8"))) | |
{ // patch TypeBinder.string | |
val field = TypeBinder.getClass.getDeclaredField("string") | |
field.setAccessible(true) | |
field.set(TypeBinder, stringUTF8) | |
} | |
{ // patch ParameterBinderFactory.stringParameterBinderFactory | |
val field = ParameterBinderFactory.getClass.getDeclaredField("stringParameterBinderFactory") | |
field.setAccessible(true) | |
field.set(ParameterBinderFactory, stringUTF8) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment