Play 2.4 - Slick 3.0.0 - DELETE not working(播放 2.4 - Slick 3.0.0 - DELETE 不工作)
问题描述
我正在尝试升级到 Slick 3.0.0 和 Play 2.4 (Scala),但是删除行不起作用.在下面的代码中,一切正常:查询所有行,插入和更新 - 除了删除.
I am trying to upgrade to Slick 3.0.0 and Play 2.4 (Scala), but deleting rows is not working. In the code below, everything works: querying all rows, inserting and updating - except delete.
package dao
import scala.concurrent.Future
import models._
import models.Tables._
import play.api.Play
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfig
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import slick.driver.JdbcProfile
class UserDAO extends HasDatabaseConfig[JdbcProfile] {
protected val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)
import driver.api._
def all(): Future[List[UserRow]] = db.run(Tables.User.result).map(_.toList)
def findByEmail(email: String): Future[Option[UserRow]] = {
db.run(Tables.User.filter(_.email === email).result.headOption)
}
def update(id: Int, newData: UserRow): Future[Int] = {
db.run(Tables.User.filter(_.id === id).update(newData))
}
def delete(id: Int): Future[Int] = {
db.run(Tables.User.filter(_.id === id).delete)
}
}
代码生成以下编译错误:
The code generates the following compilation error:
value delete is not a member of slick.lifted.Query[models.Tables.User,models.Tables.User#TableElementType,Seq]
我在application.conf中使用slick.driver.MySQLDriver$/com.mysql.jdbc.Driver,models.Tables.scala文件是slick-codegen lib自动生成的.
I am using slick.driver.MySQLDriver$ / com.mysql.jdbc.Driver in the application.conf, and the models.Tables.scala file is automatically generated by slick-codegen lib.
谁能帮我解决这个问题?谢谢!
Can anyone help me to fix this? Thanks!
推荐答案
尝试导入更具体的 API,而不是 import driver.api._
使用 import slick.driver.MySQLDriver.api._
.
Try importing a more specific API, so instead of import driver.api._
use import slick.driver.MySQLDriver.api._
.
我刚刚遇到了同样的问题,发现了这个关于 slick 的错误报告:https://github.com/playframework/play-slick/issues/249
I just had the same issue and found this bug report for slick: https://github.com/playframework/play-slick/issues/249
这篇关于播放 2.4 - Slick 3.0.0 - DELETE 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:播放 2.4 - Slick 3.0.0 - DELETE 不工作


- 在SQL中,如何为每个组选择前2行 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- SQL 临时表问题 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01