如何在 ScalaQuery 中获取类对象作为结果而不是元组?
我已经开始使用 Scala 和 ScalaQuery 开始我的第一个项目。到目前为止,两者看起来都不错并且很有前途,尽管我偶尔会遇到一些困难。
有人可以解释一下如何获取类对象(在本例中为具有大约 12 列的域案例类)而不是元组。 下面的查询返回元组,但问题是我需要表的大约 9 列(或所有列),而无需在查询产量中提供每个列名称。 Domain 类已经 * 定义了所有列,那么为什么下面的查询会返回元组而不是 Domain 对象,以便我可以使用 Domain.name、Domain.level 而不是计算返回的元组中的位置。
val ext_id = 'ns1.amazon.com'
val name = "www.getcrazy.com"
val validDomains = for {p <- Domain where { p => (p.ext_id is ext_id) && (p.domain_name is name) && (p.is_deleted is false) && (p.result_code is "1000")}} yield *
for(pp <- validDomains) {
logger.debug("State is " + pp._6 + " for domain ID - " + pp._1)
}
有什么建议吗?
谢谢, 帕万
I have started my first project in Scala and ScalaQuery. So far both are looking good and promising though I am having little difficulty once in a while.
Can someone please explain me how to get a class object (in this case Domain case class having around 12 columns) instead of tuples.
Below query is returning tuples but the problem is I need around 9 columns(or all columns) of the table without providing each column name in the query yield. Domain class already has * defining all columns then why would the query below is returning tuples instead of Domain object so that I can use Domain.name, Domain.level instead of figuring the position in tuple returned.
val ext_id = 'ns1.amazon.com'
val name = "www.getcrazy.com"
val validDomains = for {p <- Domain where { p => (p.ext_id is ext_id) && (p.domain_name is name) && (p.is_deleted is false) && (p.result_code is "1000")}} yield *
for(pp <- validDomains) {
logger.debug("State is " + pp._6 + " for domain ID - " + pp._1)
}
Any suggestion?
Thanks,
Pawan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个扩展的对象
org.scalaquery.ql.basic .BasicTable
。例如,有了这个,您可以简单地查询
CommunityTable
并获取List[Community]
返回:Create an object that extends
org.scalaquery.ql.basic.BasicTable
. For example,With this, you can simply query the
CommunityTable
and get aList[Community]
back: