Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Last active May 11, 2016 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuwei-k/1a3f7c645a6acf0f13e9a475a6947a93 to your computer and use it in GitHub Desktop.
Save xuwei-k/1a3f7c645a6acf0f13e9a475a6947a93 to your computer and use it in GitHub Desktop.
libraryDependencies += "org.scalikejdbc" %% "scalikejdbc" % "2.4.0"
scalaVersion := "2.11.8"
import scalikejdbc._
object Main {
def main(args: Array[String]): Unit = {
implicitly[TypeBinder[Price]]
implicitly[ParameterBinderFactory[Price]]
}
}
case class Price(value: Int)
object Price extends ScalikejdbcValueCompanion[Int, Price]
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