1
我目前正在玩Play和play-slick。下面的代碼給我一個錯誤value delete不是slick.lifted.Query的成員[T,T#TableElementType,Seq]
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)
}
}
錯誤:
value delete is not a member of slick.lifted.Query[T,T#TableElementType,Seq]
我已經用Google搜索了很多,但沒有辦法爲我工作。例如,我嘗試替換'import driver.api。 '與'import slick.driver.H2Driver.api。'沒有任何運氣。
我正在使用Scala 2.11.7,使用play-slick 2.0.2和Play 2.5。
另外你可能會認爲,如果你從'CrudRepository'方法返回'Future'是有意義的。這種方法不會允許您在交易中執行操作。 –
嘿,謝謝你的回答!不幸的是,這導致了另一個錯誤:http://pastebin.com/k2KDemM8 顯然,斯卡拉無法看到兩個類的驅動程序導入是相同的。 對我來說db.run總是返回一個Future,順便說一句。 – Magnus
看看我更新的答案 - 它使您的代碼編譯。 –