gpt4 book ai didi

postgresql - Slick 2.0 - 更新两列或更多列

转载 作者:行者123 更新时间:2023-11-29 14:21:32 25 4
gpt4 key购买 nike

我知道我可以更新 Slick 2.0 中的两列:

val q = for (user <- Users if user.id === id) yield (user.name, user.city)
q.update((newName, newCity))

但我已经看到类似的东西也能正常工作,这是 IMO 更好的语法:

Users.filter(_.id === id).map(u => u.name ~ u.city).update(newName, newCity)

这给了我以下错误:

value ~ is not a member of shortcut.db.Tables.profile.simple.Column

我已经导入了 PostgresDriver.simple._ 但我就是不明白为什么。我也使用代码生成器。

提前致谢!

最佳答案

那是因为 ~ 方法是 moved out of the normal import scope适用于 Slick 2.0。您可以按原样使用元组:

Users.filter(_.id === id).map(u => (u.name, u.city)).update((newName, newCity))

或导入必要的 TupleMethods对象:

import scala.slick.util.TupleMethods._
Users.filter(_.id === id).map(u => u.name ~ u.city).update((newName, newCity))

关于postgresql - Slick 2.0 - 更新两列或更多列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24174839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com