简体   繁体   English

值删除不是slick.lifted.Query [T,T#TableElementType,Seq]的成员

[英]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 . 其中Tableslick.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.

相关问题 Scala Slick 2.0:从Query [Mixed,T#TableElementType]转换为Query [T,T#TableElementType] - Scala Slick 2.0: converting from Query[Mixed, T#TableElementType] to Query[T, T#TableElementType] value~不是slick.lifted.Rep [Option [Int]]的成员 - value ~ is not a member of slick.lifted.Rep[Option[Int]] 错误:值seq不是对象slick.dbio.DBIO的成员 - Error: value seq is not a member of object slick.dbio.DBIO isEmpty值不是slick.lifted.Rep [Option [java.time.LocalDateTime]]的成员 - value isEmpty is not a member of slick.lifted.Rep[Option[java.time.LocalDateTime]] 是否可以在Slick查询模板中使用List或Set类型的参数? (提升的API) - Are parameters of type List or Set in Slick Query Templates possible? (Lifted API) Slick 2.0:如何将提升的查询结果转换为案例类? - Slick 2.0: How to convert lifted query results to a case class? 将scala.slick.lifted.Query转换为案例类 - Converting scala.slick.lifted.Query to a case class 如何使用提升查询和选项列进行简单的平滑插入 - How make simple slick insert with Lifted query and Option columns 推断的类型参数[Boolean]不符合方法过滤器的类型参数范围[T &lt;:slick.lifted.Rep [_]] - inferred type arguments [Boolean] do not conform to method filter's type parameter bounds [T <: slick.lifted.Rep[_]] 平滑取消对对象的更新 - Slick lifted update on an Object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM