我使用slickdb编写了以下代码:
val action: DBIOAction[Int, NoStream, Effect] =
for {
id <- sql"select id from product where name = $name".as[Int].head
_ <- sql"update product set description = ${description(id, name)}".asUpdate if id != 5
} yield id
db.run(action)使用此代码,如果为id != 5,操作将不会返回id。这不是我想要的。我希望只有在id != 5的情况下才执行set description更新,同时dbaction必须返回独立的id,无论是否为id != 5。我如何才能做到这一点?
发布于 2019-12-18 01:26:43
你可能需要这样的东西:
val action: DBIOAction[Int, NoStream, Effect] =
for {
id <- sql"select id from product where name = $name".as[Int].head
} yield {
if (id != 5) {sql"update product set description = ${description(id, name)}".asUpdate }
id
}https://stackoverflow.com/questions/59363260
复制相似问题