Skip to content

Commit

Permalink
doobie: example of how to insert IO stream
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindberg committed Nov 15, 2023
1 parent 48815a0 commit dbf7811
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions typo-tester-doobie/src/scala/adventureworks/ArrayTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import adventureworks.customtypes.*
import adventureworks.public.pgtest.{PgtestRepoImpl, PgtestRow}
import adventureworks.public.pgtestnull.{PgtestnullRepoImpl, PgtestnullRow}
import adventureworks.public.{Mydomain, Myenum}
import cats.effect.IO
import doobie.{ConnectionIO, WeakAsync}
import io.circe.Encoder
import org.scalactic.TypeCheckedTripleEquals
import org.scalatest.Assertion
Expand Down Expand Up @@ -62,6 +64,23 @@ class ArrayTest extends AnyFunSuite with TypeCheckedTripleEquals {
} yield assertJsonEquals(before, after)
}
}

// this test is doobie-specific
test("can stream insert IO stream") {
val before = List(ArrayTestData.pgtestnullRow, ArrayTestData.pgtestnullRowWithValues)
val beforeIOStream: fs2.Stream[IO, PgtestnullRow] = fs2.Stream.emits(before).covary[IO]

WeakAsync.liftK[IO, ConnectionIO].use { liftK =>
val transaction = for {
_ <- pgtestnullRepo.insertStreaming(beforeIOStream.translate(liftK), 1)
after <- pgtestnullRepo.selectAll.compile.toList
} yield assertJsonEquals(before, after)

import doobie.syntax.all.*

transaction.transact(withConnection.testXa)
}
}
}

object ArrayTestData {
Expand Down

0 comments on commit dbf7811

Please sign in to comment.