[英]Slick table Query: Trouble with recognizing values
Can anyone tell me why in this case: 谁能告诉我为什么在这种情况下:
Query(Users) foreach {case (userId, userName) =>
println(userId + ", " + userName) }
Scala recognizes userId, but in this case: Scala可以识别userId,但是在这种情况下:
val l = List[(Int, String)]()
Query(Users) foreach {
case (userId, userName) =>
l::(foo(List[(userId, userName)]))
}
it doesnt? 不是吗? (as in, the userId on the right of the "=>" is recognized in the second case but not the first) (例如,在第二种情况下会识别“ =>”右侧的userId,但在第一种情况下不会识别)
Users is a slick-mounted database that looks like this: Users是一个光滑安装的数据库,如下所示:
object Users extends Table[(Int, String)]("Users") {
def userId = column[Int]("UserId", O.PrimaryKey, O.AutoInc)
def userName = column[String]("UserName")
def * = userId ~ userName
}
I think what you mean is: 我认为您的意思是:
l::(foo(List((userId, userName))))
When you put stuff between the square brackets, you are attempting to type the list and I assume you actually wanted to add the Tuple
of userId
and userName
to a List instead. 当您将内容放在方括号之间时,您正在尝试键入列表,并且我假设您实际上是想将userId
和userName
的Tuple
添加到List中。
You could also write it like this if all you wanted to do was put it into that List
and you did not need that Tuple
extractor: 如果您只想将所有内容放入该List
,而无需该Tuple
提取器,则也可以这样编写:
Query(Users) foreach { tup =>
l::(foo(List(tup)))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.