I haven't used Slick, I'd be interested, if you have the time, in an elaboration with examples on this stuff.
I haven't used Slick, I'd be interested, if you have the time, in an elaboration with examples on this stuff.
For instance this is an example from Diesel:
Post::belonging_to(user).load(&connection)
And this is how it would look like in Slick:
Post.filter(_.userID === 1).result
So both of the above would translate into SQL "SELECT * FROM posts WHERE user_id = 1", however Slick is more explicit whereas Diesel definitely feels like an ORM. The tripple equals in Slick example for instance is a nice touch and an example of operator overloading, because userID could be of type Integer or Option[Integer] (nullable field) and it would work both ways.
I personally find "ORM" to be such a broad term as to be almost meaningless. This may be a personal problem :)
I see now. I am pretty sure that you could write
posts.filter(user_id.eq(1)).load(&connection)
if you wanted; the belonging_to is just fancier and a bit shorter.Anyway, thank you! I've mentally filed a "check out Slick sometime" bug for my infinite personal-to-do list :)
val base = for {
ur <- UserRole
u <- ur.user
r <- ur.role
} yield (ur, u, r)
val withManager = for {
(ur, u, r) <- base
ts <- TeamStaff if u.id === ts.userId
} yield (ur, u, r, ts)
val teams = for {
(_, _, _, ts) <- withManager
t <- Team if t.id === ts.teamId
} yield (ts, t)
You can slice and dice a schema however you like, building up queries from other queries, none of which are run until you execute them. Basically you get semantically the same query plans as you'd get writing plain sql, but it's all type checked, sql injection safe, and compiled (queries generally are generated at compile time, not run time).Quill, another Scala FRM library, is worth checking out in this regard, as is Haskell's Esqueleto.
I do agree that things like associations are an entirely new layer of abstraction.