Executing non-database actions in a transaction in Slick 3

前端 未结 1 599
囚心锁ツ
囚心锁ツ 2021-01-31 17:49

I\'m having trouble understanding the new Slick DBIOAction API, which does not seem to have a lot of examples in the docs. I am using Slick 3.0.0, and I need to exe

相关标签:
1条回答
  • 2021-01-31 18:16

    Try it this way :

    val compositeAction = (for {
      rawTypes <- TableQuery[DBType].result
      pair <- DBIO.sequence(rawTypes.groupBy(_.projectId).toSeq.map(group => DBIO.successful(group)))
      counts <- DBIO.sequence(pair.head._2.map(aType => sql"""select count(*) from messages where type_id = ${aType.id}""".as[Int]))
    } yield (pair.head._1, pair.head._2.zip(counts))).transactionally
    
    0 讨论(0)
提交回复
热议问题