Reputation: 423
My case class
case class Entry(id: Int, title: String, content: String,
publishedDate: Date, views: Int)
The Schena
class Entries(tag: Tag) extends Table[Entry](tag, "ENTRIES") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def title = column[String]("title")
def content = column[String]("content")
def publishedDate = column[Date]("published_date")
def views = column[Int]("views")
override def * = (id, title, content, publishedDate, views) <> (Entry.tupled, Entry.unapply)
}
val entries = TableQuery[Entries]
My query:
def byId(id: Rep[Int]) = for (entry <- entries if entry.id === id) yield entry.first
val entryById = Compiled(byId _)
def get(id: Int): Option[Entry] = db.Schema.entryById(id).result.run(DB)
When I run I got this error: No matching Shape found. Slick does not know how to map the given types.
Play: 2.4 Scala: 2.11.6 Slick: 3.1.1
EDIT: I've also got "value first is not a member of db.Schema.Entries" and a similiar error for "result"
Upvotes: 0
Views: 1759
Reputation: 1682
You may be using java.util.Date
. I think java.sql.Date
and java.sql.Timestamp
are supported out of the box, but not java.util.Date
.
You easily fix this by switching to java.sql.Date
or you could have created a MappedColumnType to tell slick how to use it.
implicit val javaUtilDateColumnType = MappedColumnType.base[java.util.Date, java.sql.Date](
ud => new java.sql.Date(ud.getTime), sd => new java.util.Date(sd.getTime)
)
Upvotes: 1
Reputation: 3887
Methods first
and fistOption
are removed in slick 3.0.0. Use head
or headOption
.
Upvotes: 2