Skip to content

Instantly share code, notes, and snippets.

@ryantanner
Created January 27, 2013 19:04
Show Gist options
  • Save ryantanner/4649815 to your computer and use it in GitHub Desktop.
Save ryantanner/4649815 to your computer and use it in GitHub Desktop.
def testMappedType {
sealed trait Bool
case object True extends Bool
case object False extends Bool
implicit val boolTypeMapper = MappedColumnType.base[Bool, Int](
{ b =>
assertNotNull(b)
if(b == True) 1 else 0
}, { i =>
assertNotNull(i)
if(i == 1) True else False
}
)
object T extends Table[(Int, Bool, Option[Bool])]("t2") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def b = column[Bool]("b")
def c = column[Option[Bool]]("c")
def * = id ~ b ~ c
}
T.ddl.create
(T.b ~ T.c).insertAll((False, None), (True, Some(True)))
assertEquals(Query(T).list.toSet, Set((1, False, None), (2, True, Some(True))))
assertEquals(T.where(_.b === (True:Bool)).list.toSet, Set((2, True, Some(True))))
assertEquals(T.where(_.b === (False:Bool)).list.toSet, Set((1, False, None)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment