Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View SQL query in Slick

Tags:

sql

scala

slick

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?

like image 998
src091 Avatar asked May 02 '14 18:05

src091


People also ask

What is plain SQL?

The Plain SQL API allows a developer to run any SQL statement onto the database. Even though specifying parameter values is easy and straightforward, it doesn't stop a developer to embed a value directly into the SQL statement instead of using parameters.

What does group by do SQL?

The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country". The GROUP BY statement is often used with aggregate functions ( COUNT() , MAX() , MIN() , SUM() , AVG() ) to group the result-set by one or more columns.

What is Slick db?

Slick is an advanced, comprehensive database access library for Scala with strongly-typed, highly composable APIs. Slick makes it easy to use your database in a way that's natural to it.


1 Answers

Slick 2.X:

You can print the query statement as shown on the Slick documentation:

val invoker = q.invoker val statement = q.selectStatement 

For other type of statements look at insertStatement, deleteStatement and updateStatement.

Slick 3.X:

val res = table.filter(_.id === 1L).result res.statements.foreach(println) 

Docs.

like image 103
Ende Neu Avatar answered Sep 19 '22 18:09

Ende Neu