compilation error involving effect type in DBIOAction

328 views
Skip to first unread message

Ambrose Laing

unread,
Aug 26, 2015, 7:26:11 PM8/26/15
to Slick / ScalaQuery
Hi all,
I adapted some code from: http://blog.scalac.io/2015/07/09/slick-3-overview.html
and obtained the following:

---------------
  private val usersQuery: TableQuery[Users] = TableQuery[Users]

  private val createAction: DBIO[Unit] =
    usersQuery.schema.create

  private val tablesExistAction: DBIO[Boolean] = MTable.getTables.map { tables =>
    val names = Vector(usersQuery.baseTableRow.tableName)
    names.intersect(tables.map(_.name.name)) == names
  }

  def createIfNotExist(): Future[Unit] =
    db.run(
      tablesExistAction.flatMap(
        exist => if (!exist)
          createAction
        else
          SuccessAction{}
      ))
-----------

And now I have a compilation error as follows:

-----------
[error] /home/mylogin/my/project/app/model/Models.scala:173: type mismatch;
[error]  found   : Boolean => slick.dbio.DBIOAction[Unit,slick.dbio.NoStream,Nothing]
[error]  required: Boolean => slick.dbio.DBIOAction[Unit,slick.dbio.NoStream,E2]
[error]         exist => if (!exist)
[error]               ^
[error] one error found
-------------

The types match except for the third type parameter in the DBIOAction.
I would appreciate any pointers on how to fix this error.

Thanks,

Ambrose

Ambrose Laing

unread,
Aug 26, 2015, 7:27:44 PM8/26/15
to Slick / ScalaQuery
Update: I'm using Play 2.4.2, Slick 3.0.2 and play-slick 1.0.1.

Richard Dallaway

unread,
Aug 27, 2015, 5:17:19 AM8/27/15
to Slick / ScalaQuery
I think you should be able to help the compiler out by giving the types on flatMap. Something like...

tablesExistAction.flatMap[Boolean, dbio.NoSream, dbio.Effect.All] { exists => ... etc }

Apologies I've not had a chance to create an example project an try that out, though.  I'd like to know if it, or something like it, works for you.

Richard




--

---
You received this message because you are subscribed to the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaquery+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/04323041-aeb7-4f48-a187-5af5def6269c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ambrose Laing

unread,
Aug 27, 2015, 7:40:09 AM8/27/15
to Slick / ScalaQuery
Hi Richard,
Your suggestion solved the problem, with the very minor tweak of replacing Boolean with Unit (as the first type param). 
Thanks for the help!,
Ambrose

Richard Dallaway

unread,
Aug 27, 2015, 9:53:49 AM8/27/15
to Slick / ScalaQuery
Great - thanks for letting me know.

Reply all
Reply to author
Forward
0 new messages