* 带大小写的投影 class
* projection with case class
所以我在关注:http://slick.typesafe.com/doc/3.0.2/gettingstarted.html 现在我想使用 case 类 而不是将每个模型定义为元组。
所以我有:
case class Character(id: Long, foreName: String, middleNames: String, lastName: String, age: Int)
//class Characters(tag: Tag) extends Table[(Int, String, String, String, Int)](tag, "characters")
class Characters(tag: Tag) extends Table[Characters](tag, "characters")
{
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def foreName = column[String]("forename")
def middleNames = column[String]("middlenames")
def lastName = column[String]("lastname")
def age = column[Int]("age")
// def * = (id, foreName, middleNames, lastName, age)
def * = (id, foreName, middleNames, lastName, age) <> (Character.tupled, Character.unapply _)
}
但我得到:
Expression of type MappedProjection[Character, (Long, String, String,
String, Int)] doesn't conform to expected type ProvenShape[Characters]
但这是为什么呢?它基本上与:http://de.slideshare.net/rebeccagrenier509/slick-learn2 幻灯片 7 相同。即使那只是 Slick 2,我如何在 Slick 3 中实现相同的效果?
看起来你想要 ... extends Table[Character]
,而不是 ... extends Table[Characters]
。
所以我在关注:http://slick.typesafe.com/doc/3.0.2/gettingstarted.html 现在我想使用 case 类 而不是将每个模型定义为元组。
所以我有:
case class Character(id: Long, foreName: String, middleNames: String, lastName: String, age: Int)
//class Characters(tag: Tag) extends Table[(Int, String, String, String, Int)](tag, "characters")
class Characters(tag: Tag) extends Table[Characters](tag, "characters")
{
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def foreName = column[String]("forename")
def middleNames = column[String]("middlenames")
def lastName = column[String]("lastname")
def age = column[Int]("age")
// def * = (id, foreName, middleNames, lastName, age)
def * = (id, foreName, middleNames, lastName, age) <> (Character.tupled, Character.unapply _)
}
但我得到:
Expression of type MappedProjection[Character, (Long, String, String, String, Int)] doesn't conform to expected type ProvenShape[Characters]
但这是为什么呢?它基本上与:http://de.slideshare.net/rebeccagrenier509/slick-learn2 幻灯片 7 相同。即使那只是 Slick 2,我如何在 Slick 3 中实现相同的效果?
看起来你想要 ... extends Table[Character]
,而不是 ... extends Table[Characters]
。