我有一个 Scala 编译错误,我无法找到任何信息。我正在使用 slick 3.0 并收到编译错误
value ~ is not a member of slick.lifted.Rep[Option[Int]]
我相信这个问题与我使用选项来表示我的 ID 字段的方式有关。
我已尝试按照此答案id.?
中的建议添加到 id 字段,但我仍然遇到同样的编译错误。slick 3.0 有什么变化吗?
我的代码如下:
import slick.driver.H2Driver.api._
import scala.concurrent.ExecutionContext.Implicits.global
case class Recipe(id: Option[Int] = None, name: String, instructions: String, ingredients: String)
object AddFixtures {
class Recipes(tag: Tag) extends Table[Recipe](tag, "recipe") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
def instructions = column[String]("instructions")
def ingredients = column[String]("ingredients")
def * = id ~ name ~ instructions ~ ingredients <> (Recipe, Recipe.unapply _)
}
val recipes = TableQuery[Recipes]
val setup = DBIO.seq(
recipes.schema.create,
recipes += Recipe(None, "Chicken with Avocado", "Mix it up", "Chicken, Avocado")
)
def apply() = {
val db = Database.forConfig("h2mem1")
try db.run(setup)
finally db.close
}
}