Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What SQL access layer to use for simple reading in Play-Scala?

I will be implementing a read-only web application in Play 2.1 (Scala). Since I'll only be doing reading and marshaling the data read to JSON I would like to avoid any other DSLs and mappings.

I've done similar projects in .NET/C# using dapper-dot-net and was very happy with the way things turned out. No fuss and not much boiler plate.

I am currently looking at:

  • anorm (anormtyped looks very promising too, but is probably to early to adopt. Avoiding the manual mapping of variables to case class constructor parameters seems awesome.)
  • prequel
  • slick - because it is supposed to be the primary way of doing SQL in 2.1 and mainly the plain SQL API
like image 490
jl. Avatar asked Jan 24 '13 09:01

jl.


1 Answers

Slick is very good. Make sure you check out this short book about it - it's very good at explaining some basics. Along with the docs it would get you forward quickly. Also, note that the docs in github are better - the latest haven't been published yet.

Using the plain sql option is very well supported. With plain sql queries you don't much in terms of type checking, though. Otherwise, using Scala 2.10 doing a plain query is as easy as:

sql"select * from coffees where name = $name".as[Coffee]

This will even protect you from sql injction, as $name is not actually in the query. See the docs for more information.

like image 141
Emil Ivanov Avatar answered Oct 03 '22 17:10

Emil Ivanov