1
試圖圍繞光滑的3 api包裹我的頭。油滑3交易如何
我有這些方法的簽名:
def findById(id: Long): DBIO[Option[Project]] =
Projects.filter(_.id === id).result.headOption
def insert(Task: Task): DBIO[Long] =
Tasks returning Tasks.map(_.id) += Task
,我想在我的控制器的單個事務中運行。
我的代碼目前看起來是這樣的,是不是事務:
def addTaskToProject(taskName: String, projectId: Long) = Action.async { implicit rs =>
val query = for {
Some(project) <- projectDAO.findById(projectId)
id <- taskDAO.insert(Task(0, "blue", project.id))
}yield id
val result = dbConfig.db.run(query)
result.map{ taskId =>
Ok("I have created a new task: " + taskId)
}
}
1)我想這樣做只是這一點:
val result = dbConfig.db.run(query).transactionally
但給了我這個錯誤:
... value transactionally is not a member of scala.concurrent.Future[Long]
2)然後我試過這個:
val result = dbConfig.db.run(query.transactionally)
,並得到這個錯誤:
... value transactionally is not a member of slick.dbio.DBIOAction[Long,slick.dbio.NoStream,slick.dbio.Effect.All with slick.dbio.Effect.All]
我怎樣才能得到這個簡單的例子來運行?
感謝提示。還沒有工作(見問題)。我將如何應用隱式對話? – nemoo
找到了。問題是,這是缺少的:import dbConfig.driver.api._ – nemoo