在 Slick 3.0.0-RC3 中更新行,使用
Updating Row in Slick 3.0.0-RC3, using
这就是我使用 Slick 2.1
更新一行 table 的方法
private def updateEntity(id: Long, row: TTable#TableElementType) = {
db.withSession { implicit session =>
val result = query.filter(_.id === id).update(row)
result.toLong
}
}
我升级到 Reactive Slick 后,db.withSession
显示弃用警告,因为 withSession 已弃用。是什么
用于更新行的基于操作的 api 语法。
Slick 3.0 使用纯函数式单子I/O,没有副作用。在基于 API 的 Action 中,您将不得不使用 db.run
,它将使用 Query
和 return 一个 Future
.
所以在你的情况下,它将是
private def updateEntity(id: Long, row: TTable#TableElementType): Future[Long] = {
db.run(query.filter(_.id === id).update(row)).map(_.toLong)
}
}
这就是我使用 Slick 2.1
更新一行 table 的方法private def updateEntity(id: Long, row: TTable#TableElementType) = {
db.withSession { implicit session =>
val result = query.filter(_.id === id).update(row)
result.toLong
}
}
我升级到 Reactive Slick 后,db.withSession
显示弃用警告,因为 withSession 已弃用。是什么
用于更新行的基于操作的 api 语法。
Slick 3.0 使用纯函数式单子I/O,没有副作用。在基于 API 的 Action 中,您将不得不使用 db.run
,它将使用 Query
和 return 一个 Future
.
所以在你的情况下,它将是
private def updateEntity(id: Long, row: TTable#TableElementType): Future[Long] = {
db.run(query.filter(_.id === id).update(row)).map(_.toLong)
}
}