Reputation: 495
I am trying to do this (on Play Framework):
db.run(users.filter(_.id === id).map(_.deleted).update(Option(DateTime.now)))
But it's throwing a compilation error:
No matching Shape found. Slick does not know how to map the given types. Possible causes: T in Table[T] does not match your * projection, you use an unsupported type in a Query (e.g. scala List), or you forgot to import a driver api into scope. Required level: slick.lifted.FlatShapeLevel Source type: slick.lifted.Rep[Option[org.joda.time.DateTime]] Unpacked type: T Packed type: G
Version of Slick 3.0.3. How can i fix this bug?
class UserTable(tag: Tag) extends Table[User](tag, "user") {
def id = column[Int]("id")
def name = column[String]("name")
def age = column[Int]("age")
def deleted = column[Option[DateTime]]("deleted")
override def * =
(id, name, age, deleted) <> ((User.apply _).tupled, User.unapply)
}
case class User(
id: Int = 0,
name: String,
age: Int,
deleted: Option[DateTime] = None
)
Upvotes: 1
Views: 2096
Reputation: 86
When you define your table, there is a column type mapper in scope for DateTime
. Something like
implicit val dtMapper = MappedColumnType.base[org.joda.time.DateTime, Long](
dt => dt.getMillis,
l => new DateTime(l, DateTimeZone.UTC)
)
for example. This mapper must also be in scope at the location where you construct your query, otherwise Slick will not know how to convert what you've written into a SQL query.
You can either import the mapper, if you would like to keep the query separate from the table, or define the query in the same file where you define UserTable
. A common pattern is to wrap the table in a trait, say UserRepository
, and define both the table and the queries within that trait.
See this page for more information on how implicit scope works.
Upvotes: 2