Last active
May 11, 2016 05:44
-
-
Save xuwei-k/1a3f7c645a6acf0f13e9a475a6947a93 to your computer and use it in GitHub Desktop.
another way of https://github.com/scalikejdbc/scalikejdbc/pull/519 ?
This file contains 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
libraryDependencies += "org.scalikejdbc" %% "scalikejdbc" % "2.4.0" | |
scalaVersion := "2.11.8" |
This file contains 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._ | |
object Main { | |
def main(args: Array[String]): Unit = { | |
implicitly[TypeBinder[Price]] | |
implicitly[ParameterBinderFactory[Price]] | |
} | |
} |
This file contains 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
case class Price(value: Int) | |
object Price extends ScalikejdbcValueCompanion[Int, Price] |
This file contains 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._ | |
abstract class ScalikejdbcValueCompanion[A, B](implicit T: TypeBinder[A], P: ParameterBinderFactory[A]) extends (A => B) { | |
def unapply(value: B): Option[A] | |
final implicit val binder: TypeBinder[B] = T.map(this) | |
final implicit val unbinder: ParameterBinderFactory[B] = P.xmap(this, unapply(_).get) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment