scala 在 Slick 中查看 SQL 查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23434286/
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
View SQL query in Slick
提问by src091
Is there a way to observe an SQL statement that will be generated by Query?
For example, I have this:val q = actions.filter(v => v.actionHash === hash && v.carriedAt > past)
Can I view its underlying raw SQL?
有没有办法观察将由Query?生成的 SQL 语句?
例如,我有这个:val q = actions.filter(v => v.actionHash === hash && v.carriedAt > past)
我可以查看其底层的原始 SQL 吗?
回答by Ende Neu
Slick 2.X:
光滑2.X:
You can print the query statement as shown on the Slick documentation:
您可以打印查询语句,如Slick 文档中所示:
val invoker = q.invoker
val statement = q.selectStatement
For other type of statements look at insertStatement, deleteStatementand updateStatement.
对于其他类型的语句,请查看insertStatement,deleteStatement和updateStatement。
Slick 3.X:
光滑 3.X:
val res = table.filter(_.id === 1L).result
res.statements.foreach(println)
Docs.
文档。
回答by binshi
For slick 3.0
对于 slick 3.0
println(sortedQuery.result.statements.headOption)

