Getting result from a database sequence in Slick 3.0.0

34 views
Skip to first unread message

Debasish Sena

unread,
Mar 29, 2016, 8:46:46 AM3/29/16
to Slick / ScalaQuery
I am trying to get the result of a query which is executed as a part of a sequence of actions passed as a parameter to DBIO.sequence() method of Slick 3.0. Below is the code snippet for the same.

val query = for {
 (tt, th) <- tmpTrades join TableQuery[TrdHeader] on (_.tradeNum === _.tradeNum)
 } yield (tt.tradeNum, th.internalInd, th.tradeStatusInd, th.tradeDt,   th.tradeInputDt, th.lastModifyDt)

val queryAction = query.result

val actions = Seq(tmpTrades.schema.create, tmpTrades ++= trades.toSeq: _*, queryAction, tmpTrades.schema.drop)

val resultFuture = db.run(DBIO.sequence(actions))
I want the result of DBIO.sequence(actions) as a tuple of six attributes corresponding to the yield clause of the query and assign it to resultFuture variable. How can I achieve the same?

Thanks.

Julien L.

unread,
Mar 29, 2016, 9:09:13 AM3/29/16
to Slick / ScalaQuery
I think you can easily express these operations with a for comprehension.

Something like that:

val operations = for {
  _
<- tmpTrades.schema.create
  _
<- (tmpTrades ++= trades.toSeq)
  result
<-
query.result
  _
<-
tmpTrades.schema.drop
} yield result

val resultFuture
= db.run(operations
.head)
Reply all
Reply to author
Forward
0 new messages