Skip to content
Use slick databases with zio!
Scala
Branch: master
Clone or download
Roberto Leibman
Roberto Leibman tech refresh
Latest commit 3f75796 Jul 8, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
project First checkin Jul 8, 2019
src First checkin Jul 8, 2019
.gitignore travis Jul 8, 2019
.scalafmt.conf First checkin Jul 8, 2019
.travis.yml travis Jul 8, 2019
LICENSE Initial commit Jul 8, 2019
README.md travis Jul 8, 2019
build.sbt tech refresh Jul 8, 2019

README.md

ZIO-Slick

CI Release
Build Status Release Artifacts

Integration between Slick and ZIO

Getting started

Add zio-slick dependency to your build.sbt:

libraryDependencies += "net.leibman" %% "zio-slick" % "0.1.0"

Example of usage:

    //An example of a Slick DBIO call.
      val action: DBIO[Int] = {
        import profile.api._
        sql"select 1".as[Int].head
      }


    // Create a database
    val db =
      profile.api.Database.forDriver(org.h2.Driver.load(), "jdbc:h2:mem:")
      
    // Create a zio runtime that has a Slick Database (we add the clock so we can do time outs)
    val dbRuntime =
      Runtime(new SlickDatabase with Clock.Live { val database = db }, PlatformLive.Default)

    val testRuntime = Runtime(12, PlatformLive.Default)

    dbRuntime.unsafeRun(action) // shouldBe 1

    val sumOfZIO: SlickZIO[Int] = for {
      a <- SlickZIO(action)
      b <- SlickZIO(action)
    } yield a + b

    dbRuntime.unsafeRun(sumOfZIO) // shouldBe 2

    // Do it with a timeout (it returns Option[Int] instead of Int.

    import scala.concurrent.ExecutionContext.Implicits.global

    val sumOfDBIO: DBIO[Int] = for {
      a <- action
      b <- action
    } yield a + b

    dbRuntime.unsafeRun(sumOfDBIO.timeout(5 seconds)) // shouldBe Option(2)

You can’t perform that action at this time.