Created
June 26, 2019 16:48
-
-
Save rleibman/e0b541852013a7c8b03179d33e5e6dfa to your computer and use it in GitHub Desktop.
Revisions
-
rleibman renamed this gist
Jun 26, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
rleibman created this gist
Jun 26, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ package slickzio import org.scalatest.{FlatSpec, Matchers} import slick.basic.BasicBackend import slick.dbio.DBIO import slick.jdbc.{H2Profile, JdbcProfile} import zio.internal.PlatformLive import zio.{Runtime, ZIO} class SlickZioSpec extends FlatSpec with Matchers { implicit val profile: JdbcProfile = H2Profile val action: DBIO[Int] = { import profile.api._ sql"select 1".as[Int].head } type SlickZIO[T] = ZIO[BasicBackend#DatabaseDef, Throwable, T] object SlickZIO { def apply[T](action: DBIO[T]): SlickZIO[T] = { for { db <- ZIO.environment[BasicBackend#DatabaseDef] res <- ZIO.fromFuture(implicit executionContext => db.run(action)) } yield res } } implicit def DBIO2SlickZIO[T](dbio: DBIO[T]): SlickZIO[T] = SlickZIO(dbio) "all manual: simple select using zio" should "also work" in { import profile.api._ val dbRuntime = Runtime(Database.forDriver(org.h2.Driver.load(), "jdbc:h2:mem:"), PlatformLive.Default) dbRuntime.unsafeRun(action) shouldBe 1 } }