gpt4 book ai didi

scala - * 案例类投影

转载 作者:行者123 更新时间:2023-12-02 06:55:28 24 4
gpt4 key购买 nike

所以我在关注:http://slick.typesafe.com/doc/3.0.2/gettingstarted.html现在我想使用案例类而不是将每个模型定义为元组。

所以我有:

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]

关于scala - * 案例类投影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32203057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com