Akka, Spray and Play to come Together
scalalearn.com
scalalearn.com
It speaks nicely to what it should and shouldn't be used for at a high enough level that people new to it can understand quickly.
> SQL is already the best DSL for accessing relational databases.
I have no real opinion on the matter, as someone who doesn't like working with databases very much, I appreciate the comfort a ORM mapper gives me, but so far, all my web apps have been very small and basically trivial, so I don't know how they work with bigger projects.
[0]: http://www.playframework.com/documentation/2.2.x/ScalaAnorm
def findById(userId: Int)(implicit session: Session): Option[User] = { val query = for{ u <- Users if u.id === userId } yield u query.firstOption }
http://stackoverflow.com/questions/16461260/select-single-ro...
However, that's not even the brink of the iceberg. Try finding out how to update multiple fields in an object. Say you retrieve a User object, and you want to set a new email, zip, and address. I'd suppose, this would work with simple getters and setters, i.e.:
user = Users.get(user_id) user.email = new_mail user.zip = new_zip user.address = new_address
Instead, you have to do this:
val map = Query(User) .filter(_.id === user_id) .map(ab => ab.email ~ ab.zip ~ ab.address)
map.update((new_mail, new_zip, new_address))
And even that only works with updateable result sets. See: http://stackoverflow.com/questions/16757368/how-do-you-updat...
https://groups.google.com/forum/#!msg/scalaquery/ML56aZAfy3g...
Or, to quote from the stackoverflow answer above: "Typesafe, why your documentation is so bad ? I have to Google pretty much every silly thing or dig through unit-tests for hours. Please improve it. Thanks."
Now, after a lot of searching, I found solutions to all of my problems, but it took a long time, lots of Google, and almost nothing came out of their awful documentation.
All the derision that Rod Johnson got for his keynote where he mentioned the lack of ORM (among other things) as being intimidating to a beginner seems unfair.
You could reduce your first example to def findById(userId: Int)(implicit s: Session) = Users.filter(_.id === userId).firstOption
See: http://slick.typesafe.com/doc/1.0.1/lifted-embedding.html#in... and notice how much is involved in doing a simple insert into a table with a primary key.
Users.forInsert insert User(None, "Christopher", "Vogt")
Personally, I don't find that to be a lot of ceremony. Now, Slick definitely still has some problems and requires too much boilerplate, I'll certainly agree with that but I don't think this is one of those cases (though it could be improved).Edit: should add that I'm mainly familiar with the Java play framework aspects, not so much the Scala end.
In the past I've used Erlang/OTP and loved it, but with this news, I might use this instead.
So here is something I found. Its a benchmark for some of the ORM frameworks out there. Slick doesn't do too well.