3 ms·
Well, like I said Slick is not an ORM whereas Diesel is. Slick is not as much about an ORM abstraction, but writing SQL queries in Scala by leveraging it's coll
by neverminder 9y ago
Well, like I said Slick is not an ORM whereas Diesel is. Slick is not as much about an ORM abstraction, but writing SQL queries in Scala by leveraging it's collections library, taking advantage of Scala's advanced features such as operator overloading, etc.
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.
- steveklabnik 9y ago> like I said Slick is not an ORM whereas Diesel is. 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 :)
- neverminder 9y agoNo problem, I guess what I'm trying to say is that just like Rust took inspiration from Scala syntax (at least I get this feeling), maybe so could Diesel from Slick.
- rabidferret 9y agoSlick was definitely an influence on Diesel's design. I tried to have our query builder map more closely to SQL though, whereas Slick feels like it's trying to pretend it's just an Iterable.
- rabidferret 9y agoYou could just as easily write `posts.filter(user_id.eq(1)).load(&connection)`.