[英]value delete is not a member of slick.lifted.Query[T,T#TableElementType,Seq]
I am currently playing around with Play and play-slick. 我目前正在玩Play和Play-Slick。 The following code gives me an error 以下代码给我一个错误
class GenericRepository(protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider[JdbcProfile] {
import driver.api._
implicit val localDateTimeColumnType = MappedColumnType.base[LocalDateTime, Timestamp](
d => Timestamp.from(d.toInstant(ZoneOffset.ofHours(0))),
d => d.toLocalDateTime
)
protected trait GenericTable {
this: Table[_] =>
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def createdAt = column[LocalDateTime]("created_at")
def updatedAt = column[LocalDateTime]("updated_at")
}
protected class CrudRepository[T <: AbstractTable[_] with GenericRepository#GenericTable](private val tableQuery: TableQuery[T]) {
def all = db.run(tableQuery.to[List].result)
def create(obj: T#TableElementType) = db.run(tableQuery returning tableQuery.map(_.id) += obj)
def delete(id: Long) = db.run(tableQuery.filter(_.id === id).delete)
}
}
Error: 错误:
value delete is not a member of slick.lifted.Query[T,T#TableElementType,Seq]
I already googled a lot but no solution worked for me. 我已经用谷歌搜索了很多,但是没有解决方案对我有用。 For instance I tried replacing 'import driver.api. 例如,我尝试替换'import driver.api。 ' with 'import slick.driver.H2Driver.api. ”和“ import slick.driver.H2Driver.api”。 ' without any luck. '没有任何运气。
I am using Scala 2.11.7 with play-slick 2.0.2 and Play 2.5. 我正在将Scala 2.11.7与play-slick 2.0.2和Play 2.5一起使用。
EDIT: From your pasted code I see now your problem. 编辑:从您粘贴的代码,我现在看到您的问题。
Just change your definition to (I changed type parameters only): 只需将您的定义更改为(仅更改了类型参数):
protected class CrudRepository[E, T <: Table[E] with GenericRepository#GenericTable](private val tableQuery: TableQuery[T]) {
def all = db.run(tableQuery.to[List].result)
def create(obj: T#TableElementType) = db.run(tableQuery returning tableQuery.map(_.id) += obj)
def delete(id: Long) = db.run(tableQuery.filter(_.id === id).delete)
}
where Table
is slick.relational.RelationalProfile.API.Table
. 其中Table
是slick.relational.RelationalProfile.API.Table
。
Then instantiate your CrudRepository
in following way: 然后通过以下方式实例化CrudRepository
:
val crud = new CrudRepository[Redirect,RedirectsTable](Redirects)
Otherthan that it's looking good. 除了看起来不错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.