scala 如何使用 Slick Lifted Embedding 更新多个列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16757368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you update multiple columns using Slick Lifted Embedding?
提问by expert
How do you update multiple columns using Slick Lifted Embedding ? This documentdoesn't say much.
如何使用 Slick Lifted Embedding 更新多个列?这个文件没有说太多。
I expected it to be something like this
我希望它是这样的
Query(AbilitiesTable).filter((ab: AbilitiesTable.type) => ab.id === ability_id).map((ab: AbilitiesTable.type) => (ab.verb, ab.subject)).update("edit", "doc")
回答by expert
I figured it out. It should be like this
我想到了。应该是这样的
val map = Query(AbilitiesTable)
.filter(_.id === ability_id)
.map(ab => ab.verb ~ ab.context)
map.update(("", ""))
Typesafe, why your documentation is so bad ? I have to Google pretty much every silly thing or dig through unit-tests for hours. Please improve it. Thanks.
类型安全,为什么您的文档如此糟糕?我不得不谷歌几乎所有愚蠢的事情或挖掘单元测试几个小时。请改进它。谢谢。
回答by nemoo
With Slick 2.x and 3.x, this way of writing it works:
使用 Slick 2.x 和 3.x,这种编写方式有效:
Users.filter(_.id === filterId)
.map(x => (x.name, x.age))
.update(("john", 99))
Be careful to remember the extra parentheses if you are updating more than one property otherwise you might get a compiler warning.
如果您要更新多个属性,请小心记住额外的括号,否则您可能会收到编译器警告。

