Permalink
Browse files

+slick #1329 add flatten to DBIOAction

  • Loading branch information...
hepin1989 committed Oct 22, 2015
1 parent d84a7fe commit 48122359f33cd2a44deceadba4f0c9204b38aac3
@@ -109,4 +109,21 @@ class ActionTest extends AsyncTest[RelationalTestDB] {
a5.map(_ shouldBe "a5")
)
} else DBIO.successful(())
def testFlatten = {
class T(tag: Tag) extends Table[Int](tag, u"t") {
def a = column[Int]("a")
def * = a
}
val ts = TableQuery[T]
for {
_ <- db.run {
ts.schema.create >>
(ts ++= Seq(2, 3, 1, 5, 4))
}
needFlatten = for (_ <- ts.result) yield ts.result
result <- db.run(needFlatten.flatten)
_ = result shouldBe Seq(2, 3, 1, 5, 4)
} yield ()
}
}
@@ -49,6 +49,11 @@ sealed trait DBIOAction[+R, +S <: NoStream, -E <: Effect] extends Dumpable {
def flatMap[R2, S2 <: NoStream, E2 <: Effect](f: R => DBIOAction[R2, S2, E2])(implicit executor: ExecutionContext): DBIOAction[R2, S2, E with E2] =
FlatMapAction[R2, S2, R, E with E2](this, f, executor)
/** Creates a new DBIOAction with one level of nesting flattened, this method is equivalent
* to `flatMap(identity)`.
*/
def flatten[R2, S2 <: NoStream, E2 <: Effect](implicit ev : R <:< DBIOAction[R2,S2,E2]) = flatMap(ev)(DBIO.sameThreadExecutionContext)
/** Run another action after this action, if it completed successfully, and return the result
* of the second action. If either of the two actions fails, the resulting action also fails. */
def andThen[R2, S2 <: NoStream, E2 <: Effect](a: DBIOAction[R2, S2, E2]): DBIOAction[R2, S2, E with E2] = a match {

0 comments on commit 4812235

Please sign in to comment.