How can I split out a Slick interpolated query over multiple lines?

泪湿孤枕 提交于 2019-12-10 23:14:32

问题


Is there any way to split a Slick interpolated query over multiple lines in your code? My queries tend to get rather long.

So I look for something like the following:

val query = sql"select * from DOCUMENTS " + 
            sql"where language = $lang order by publication_date desc"
query.as[ResearchDocument]

But this results in

type mismatch;
 found   : scala.slick.jdbc.SQLInterpolationResult[String]
 required: String
          sql"where language = $lang order by publication_date desc"
          ^

回答1:


Ok, seems like the Scala triple quote string is the way to go:

val query = sql"""select * from DOCUMENTS
                  where language = $lang order by publication_date desc"""


来源:https://stackoverflow.com/questions/22091206/how-can-i-split-out-a-slick-interpolated-query-over-multiple-lines

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!