我想使用嵌套更新来编译查询,但出现编译错误。
我有此代码:
trait TestSlick {
val profile: slick.jdbc.JdbcProfile
import profile.api._
class Entity1(tag: Tag) extends Table[(Long, String)](tag, "ENTITY1") {
def id = column[Long]("KEY", O.PrimaryKey)
def value = column[String]("VALUE")
def * = (id, value)
}
val entity1Table = TableQuery[Entity1]
class Entity2(tag: Tag) extends Table[(Long, String)](tag, "ENTITY2") {
def id = column[Long]("KEY", O.PrimaryKey)
def value = column[String]("VALUE")
def * = (id, value)
}
val entity2Table = TableQuery[Entity2]
def _getEntity1ById(id: Rep[Long]) = entity1Table.filter(_.id === id).map(_.value)
def _getEntity2ById(id: Rep[Long]) = entity2Table.filter(_.id === id).map(_.value)
def _getEntitiesTuple(idE1: Rep[Long], idE2: Rep[Long], value1: String, value2: String) = for {
e1 <- _getEntity1ById(idE1).update(value1)
e2 <- _getEntity2ById(idE1).update(value2)
} yield (e1, e2)
val getEntitiesTuple = Compiled(_getEntitiesTuple _)
}
当我尝试编译此特征时,出现以下错误:
Error:(35, 34) Computation of type (TestSlick.this.profile.api.Rep[Long], TestSlick.this.profile.api.Rep[Long], String, String) => slick.dbio.DBIOAction[(Int, Int),slick.dbio.NoStream,slick.dbio.Effect.Write with slick.dbio.Effect.Write] cannot be compiled (as type C)
val getEntitiesTuple = Compiled(_getEntitiesTuple _)
和
Error:(35, 34) not enough arguments for method apply: (implicit compilable: slick.lifted.Compilable[(TestSlick.this.profile.api.Rep[Long], TestSlick.this.profile.api.Rep[Long], String, String) => slick.dbio.DBIOAction[(Int, Int),slick.dbio.NoStream,slick.dbio.Effect.Write with slick.dbio.Effect.Write],C], implicit profile: slick.basic.BasicProfile)C in object Compiled.
Unspecified value parameters compilable, profile.
val getEntitiesTuple = Compiled(_getEntitiesTuple _)
但我不知道为什么。
在没有update
的情况下,编译效果很好。