2
votes

I have an issue how to execute queries with slick 3.0 in the correct way

Main idea: 1) Prepare functional queries 2) execute and get List of objects

Now I can do it like this

val q = user.filter(_.id > 1)

val res = Await.result(db.run(DBIO.seq(
  q.result.map(println)
)), Duration.Inf)

but in this case I should create some var into db.run.

Could you please give me some example, how to execute slick query and get List result to the val ?

BR!

2

2 Answers

4
votes

Calling map(println) will give you a List[Unit] which is probably not what you want. Try this:

val q = user.filter(_.id > 1)
val future = db.run(q.result)
val users = Await.result(future, Duration.Inf)

users foreach println
0
votes

what you have to do is to just add the '.toList' at the end of your statement

val q = user.filter(_.id > 1)
val res = Await.result(db.run(DBIO.seq( q.result.map(println))), Duration.Inf).toList