简体   繁体   English

Scala Anorm使用列分辨率选择2个值

[英]Scala Anorm select 2 values using column resolution

According to documentation ( https://www.playframework.com/documentation/2.5.x/Anorm ), I can do the following to retrieve values from 2 columns: 根据文档( https://www.playframework.com/documentation/2.5.x/Anorm ),我可以执行以下操作以从2列中检索值:

val res: (String, Int) = SQL"SELECT text, count AS i".map(row =>
  row[String]("text") -> row[Int]("i")
)

This does not compile... 这不会编译...

Causes this: 原因如下:

Expression of type SimpleSql[(String, Int)] doesn't conform to expected type (String, Int) 类型SimpleSql [(String,Int)]的表达式不符合预期的类型(String,Int)

I'm just looking for a single method of doing this (for anorm 2.5+). 我只是在寻找一种这样做的方法(适用于2.5或更高的主动脉)。 I was using regular parsers but am looking for this more concise way of doing it. 我使用的是常规解析器,但是正在寻找这种更简洁的方法。

The code is not complete: to get a single result as such tuple, the .single combinator must be used. 代码不完整:要获得诸如元组这样的单个结果,必须使用.single组合器。

val res: (String, Int) = SQL"SELECT text, count AS i".map(row =>
  row[String]("text") -> row[Int]("i")
).single

Using Anorm flatteners is easier for tuple result: see examples 使用Anorm展平器更容易获得元组结果: 请参见示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM