Skip to content

rleibman/zio-slick

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

Use slick databases with zio!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages