Permalink
Browse files

Fix ambiguity for MappedProjection Shape

Similar to the `ShapedValue` `Shape` in
#1753 the `Shape` for
`MappedProjection` also caused ambiguities with `repColumnShape` for
single-column mappings.

(via https://support.lightbend.com/agent/case/9057)
  • Loading branch information...
szeiger committed Jul 12, 2017
1 parent 77d4ff7 commit ddb75a0f96fdde48bbb6885c4636bae204515a69
@@ -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]
@@ -62,8 +62,9 @@ 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]]
// Needs to be of higher priority thatn repColumnShape, otherwise single-column ShapedValues are ambiguous
// Need to be of higher priority than repColumnShape, otherwise single-column ShapedValues and MappedProjections are ambiguous
@inline implicit def shapedValueShape[T, U, Level <: ShapeLevel] = RepShape[Level, ShapedValue[T, U], U]
@inline 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) = ()
@@ -384,8 +385,3 @@ class MappedProjection[T, P](child: Node, mapper: MappedScalaType.Mapper, classT
}
def genericFastPath(f: Function[Any, Any]) = new MappedProjection[T, P](child, mapper.copy(fastPath = Some(f)), classTag)
}
object MappedProjection {
/** The Shape for a MappedProjection */
@inline implicit final def mappedProjectionShape[Level >: FlatShapeLevel <: ShapeLevel, T, P] = RepShape[Level, MappedProjection[T, P], T]
}

0 comments on commit ddb75a0

Please sign in to comment.