Permalink
Browse files

[backport] Fix ambiguity for MappedProjection Shape

Binary compatible backport of #1757
  • Loading branch information...
szeiger committed Jul 18, 2017
1 parent f21a58a commit 4c0130cb387da99d2bc533bce23c0c2d5f0c0344
@@ -139,6 +139,28 @@ class RelationalMapperTest extends AsyncTest[RelationalTestDB] {
implicitly[Shape[_ <: FlatShapeLevel, MyTable, _, _]]
TableQuery(new MyTable(_)).map(identity)
}
def testMappedProjectionShape = {
def toLower(s: Option[String]) = s.map(_.toLowerCase)
def toUpper(s: Option[String]): Option[Option[String]] = Some(s.map(_.toUpperCase))
case class Row(id: String, escaped: Option[String])
class T(tag: Tag) extends Table[Row](tag, u"t") {
val id = column[String]("id", O.PrimaryKey)
val name = column[Option[String]]("name")
val upperName = name.shaped <> (toLower, toUpper)
def * = (id, upperName) <> (Row.tupled, Row.unapply)
}
val ts = TableQuery[T]
seq(
ts.schema.create,
ts += Row("a", Some("foo")),
ts.map(_.name).result.map(_ shouldBe Seq(Some("FOO"))),
ts.result.map(_ shouldBe Seq(Row("a", Some("foo"))))
)
}
}
case class MyMappedID(value: Int) extends AnyVal with slick.lifted.MappedTo[Int]
@@ -63,6 +63,8 @@ object Shape extends ConstColumnShapeImplicits with AbstractTableShapeImplicits
@inline implicit final def unitShape[Level <: ShapeLevel]: Shape[Level, Unit, Unit, Unit] =
unitShapePrototype.asInstanceOf[Shape[Level, Unit, Unit, Unit]]
@inline final implicit def mappedProjectionShape[Level >: FlatShapeLevel <: ShapeLevel, T, P] = RepShape[Level, MappedProjection[T, P], T]
val unitShapePrototype: Shape[FlatShapeLevel, Unit, Unit, Unit] = new Shape[FlatShapeLevel, Unit, Unit, Unit] {
def pack(value: Mixed) = ()
def packedShape: Shape[FlatShapeLevel, Packed, Unpacked, Packed] = this
@@ -387,5 +389,6 @@ class MappedProjection[T, P](child: Node, mapper: MappedScalaType.Mapper, classT
object MappedProjection {
/** The Shape for a MappedProjection */
@inline implicit final def mappedProjectionShape[Level >: FlatShapeLevel <: ShapeLevel, T, P] = RepShape[Level, MappedProjection[T, P], T]
@deprecated("Use Shape.mappedProjectionShape instead", "3.2.1")
@inline final def mappedProjectionShape[Level >: FlatShapeLevel <: ShapeLevel, T, P] = RepShape[Level, MappedProjection[T, P], T]
}

0 comments on commit 4c0130c

Please sign in to comment.