Slick 2.0-更新两个或更多列 [英] Slick 2.0 - update two or more columns

查看:78
本文介绍了Slick 2.0-更新两个或更多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用以下代码更新Slick 2.0中的两列:

I know I can update two columns in Slick 2.0 with:

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

但是我也看到过类似的东西,这也是IMO更好的语法:

But I've seen something like this working as well which is IMO much nicer syntax:

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 ._,但我不知道为什么。我也使用代码生成器。

I have imported PostgresDriver.simple._ and I just can't figure out why. I also use the code generator.

谢谢!

推荐答案

这是因为方法是已从Slick 2.0的正常导入范围中移出。您可以使用元组,如下所示:

That is because the ~ method was moved out of the normal import scope for Slick 2.0. You can either use a tuple, just as is:

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))

这篇关于Slick 2.0-更新两个或更多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆