2

I've recently moved a project from PHP to Scala and have started working on adding database support. I'm using Slick 2.1 and am loving it so far. Everything works great, however I can't figure out how to return query results as a map (assuming this is even supported). I was previously using PHP's PDO, which returned an associative array.

Basically, instead of results being a Seq of whatever table class, I'd like to be able to retrieve them as such:

Seq(
  Map("id" -> 1, "email" -> "myEmail1", "password" -> "myPassword1"),
  Map("id" -> 2, "email" -> "myEmail2", "password" -> "myPassword1")
)

I could convert the case classes into a map, but it'd definitely be nice if I could avoid that extra step. I guess that also would't work for mapped queries. I'm pretty new to Scala and Slick, so hopefully I'm not missing something really obvious.

Thanks for the help!

  • Answered here: http://stackoverflow.com/questions/20262036/slick-query-multiple-tables-databases-with-getting-column-names – cvogt Oct 09 '14 at 00:12
  • Would it be possible to use the same approach with the Lifted Embedding API (instead of raw SQL)? I tried to get something working using that link as a guide, but unfortunately didn't get very far. – icantthinkofaname Oct 09 '14 at 03:06
  • Somewhat. You can't run it through the lifted embedding, because it is typesafe and Map[String,String] is not. But you can use the lifted embedding as a SQL builder. You can call .selectStatement on a lifted query and use that as plain SQL, e.g. with queryNA. – cvogt Oct 09 '14 at 04:40
  • Are you sure you want `String`, not `Symbol`? –  Oct 09 '14 at 10:27

0 Answers0