Question

I'm now trying to make use of Slick's compiled queries feature. For simple queries it works fine, but queries involving joins with Tuple return type cause compilation error.

Here's one of the dao methods I'm trying to rewrite with compiled queries:

def getByArticle(id: Int)(implicit session: JdbcBackend#Session) = {
      comments
        .filter(_.articleId === id)
        .leftJoin(users).on(_.userId === _.id)
        .list
    }

When I'm trying to modify it like that

val byArticleCompiled = Compiled((id: Column[Int]) => comments
  .filter(_.articleId === id)
  .leftJoin(users).on(_.userId === _.id)
)

def getByArticle(id: Int)(implicit session: JdbcBackend#Session) = byArticleCompiled(id).list

the following compilation error occurs:

[error] Computation of type CommentsRepositoryComponentImpl.this.profile.simple.Column[Int] => scala.slick.lifted.WrappingQuery[(CommentsRepositoryComponentImpl.this.Comments, CommentsRepositoryComponentImpl.this.Users),(CommentsRepositoryComponentImpl.this.Comments#TableElementType, CommentsRepositoryComponentImpl.this.Users#TableElementType)] cannot be compiled (as type C) [error] val byArticleCompiled = Compiled((id: Column[Int]) => comments

Is there any conceptual problem behind that or I'm simply doing somehting wrong?

Était-ce utile?

La solution

It seems there is a problem with the Executable typeclass for these queries produced by a join. As a work-around, appending a dummy operation like .withFilter(_ => true) makes it compile. We'll look into it for 2.0.2 (https://github.com/slick/slick/issues/746).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top