Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rleibman/zio-slick
Use slick databases with zio!
https://github.com/rleibman/zio-slick
Last synced: 26 days ago
JSON representation
Use slick databases with zio!
- Host: GitHub
- URL: https://github.com/rleibman/zio-slick
- Owner: rleibman
- License: mit
- Created: 2019-07-08T03:16:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-07-08T04:39:11.000Z (over 5 years ago)
- Last Synced: 2024-08-03T01:16:54.472Z (3 months ago)
- Language: Scala
- Size: 10.7 KB
- Stars: 16
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-zio - zio-slick
README
# ZIO-Slick
| CI | Release |
| --- | --- |
| [![Build Status][Badge-Travis]][Link-Travis] | [![Release Artifacts][Badge-SonatypeReleases]][Link-SonatypeReleases] |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 + bdbRuntime.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 + bdbRuntime.unsafeRun(sumOfDBIO.timeout(5 seconds)) // shouldBe Option(2)
```
[Link-Travis]: https://travis-ci.com/rleibman/zio-slick "circleci"
[Link-SonatypeReleases]: https://oss.sonatype.org/content/repositories/releases/net/leibman/zio-slick-core_2.12/ "Sonatype Releases"[Badge-Travis]: https://travis-ci.com/rleibman/zio-slick.svg?branch=master "Codecov"
[Badge-SonatypeReleases]: https://img.shields.io/nexus/r/https/oss.sonatype.org/net.leibman/zio-slick-core_2.12.svg "Sonatype Releases"