Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name := "tranzactio"
licenses := Seq("APL2" -> url("https://www.apache.org/licenses/LICENSE-2.0.txt"))
description := "ZIO wrapper for Scala DB libraries (e.g. Doobie)"

scalaVersion := "2.13.3"
scalaVersion := "2.13.6"



Expand Down Expand Up @@ -75,9 +75,9 @@ scalacOptions ++= Seq(



val ZioVersion = "1.0.5"
val ZioCatsVersion = "2.3.1.0"
val DoobieVersion = "0.12.1"
val ZioVersion = "1.0.8"
val ZioCatsVersion = "3.1.1.0"
val DoobieVersion = "1.0.0-M4"
val AnormVersion = "2.6.10"
val H2Version = "1.4.200"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package io.github.gaelrenoux.tranzactio

import java.sql.{Connection => JdbcConnection}

import _root_.doobie.free.KleisliInterpreter
import _root_.doobie.util.transactor.{Strategy, Transactor}
import cats.effect.Resource
import io.github.gaelrenoux.tranzactio.test.DatabaseModuleTestOps
import io.github.gaelrenoux.tranzactio.utils.ZCatsBlocker
import izumi.reflect.Tag
import zio.blocking.Blocking
import zio.interop.catz._
import zio.interop.catz.implicits.rts
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid importing this implicit inside library. It will cause, that default Blocker and Clock will be used. This can cause various problems. E.g. I use https://kamon.io/ so I have to provide my own ExecutionContexts (also for Blocking) and with this import the instrumentation does not work. I think in the library it would be better to require Blocking and Clock to be provided and then use it as in this example: https://github.com/zio/interop-cats#async (see note https://github.com/zio/interop-cats#easier-imports-at-a-cost)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hmemcpy I created related MR in your repository: hmemcpy#1

import zio.stream.ZStream
import zio.stream.interop.fs2z._
import zio.{Has, Task, ZIO, ZLayer}

import java.sql.{Connection => JdbcConnection}

/** TranzactIO module for Doobie. */
package object doobie extends Wrapper {
Expand All @@ -36,7 +35,7 @@ package object doobie extends Wrapper {
/** Converts a Doobie stream to a ZStream. Note that you can provide a queue size, default value is the same as in ZIO. */
final def tzioStream[A](q: fs2.Stream[Query, A], queueSize: Int = DefaultStreamQueueSize): TranzactIOStream[A] =
ZStream.accessStream[Connection] { c =>
c.get.transP(monadErrorInstance).apply(q).toZStream(queueSize)
c.get.transP.apply(q).toZStream(queueSize)
}.mapError(DbException.Wrapped)

/** Database for the Doobie wrapper */
Expand All @@ -49,9 +48,9 @@ package object doobie extends Wrapper {

/** How to provide a Connection for the module, given a JDBC connection and some environment. */
final def connectionFromJdbc(env: Blocking, connection: JdbcConnection): ZIO[Any, Nothing, Connection] =
ZCatsBlocker.provide(env).map { b =>
ZIO.effectTotal {
val connect = (c: JdbcConnection) => Resource.pure[Task, JdbcConnection](c)
val interp = KleisliInterpreter[Task](b).ConnectionInterpreter
val interp = KleisliInterpreter[Task].ConnectionInterpreter
val tran = Transactor(connection, connect, interp, Strategy.void)
Has(tran)
}
Expand Down
13 changes: 0 additions & 13 deletions src/main/scala/io/github/gaelrenoux/tranzactio/utils/package.scala

This file was deleted.

6 changes: 3 additions & 3 deletions src/samples/scala/samples/anorm/LayeredApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ object LayeredApp extends zio.App {
/** Main code for the application. Results in a big ZIO depending on the AppEnv. */
def myApp(): ZIO[AppEnv, DbException, List[Person]] = {
val queries: ZIO[Connection with AppEnv, DbException, List[Person]] = for {
_ <- console.putStrLn("Creating the table")
_ <- console.putStrLn("Creating the table").orDie
_ <- PersonQueries.setup
_ <- console.putStrLn("Inserting the trio")
_ <- console.putStrLn("Inserting the trio").orDie
_ <- PersonQueries.insert(Person("Buffy", "Summers"))
_ <- PersonQueries.insert(Person("Willow", "Rosenberg"))
_ <- PersonQueries.insert(Person("Alexander", "Harris"))
_ <- console.putStrLn("Reading the trio")
_ <- console.putStrLn("Reading the trio").orDie
trio <- PersonQueries.list
} yield trio

Expand Down
6 changes: 3 additions & 3 deletions src/samples/scala/samples/doobie/LayeredApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ object LayeredApp extends zio.App {
/** Main code for the application. Results in a big ZIO depending on the AppEnv. */
def myApp(): ZIO[AppEnv, DbException, List[Person]] = {
val queries: ZIO[Connection with AppEnv, DbException, List[Person]] = for {
_ <- console.putStrLn("Creating the table")
_ <- console.putStrLn("Creating the table").orDie
_ <- PersonQueries.setup
_ <- console.putStrLn("Inserting the trio")
_ <- console.putStrLn("Inserting the trio").orDie
_ <- PersonQueries.insert(Person("Buffy", "Summers"))
_ <- PersonQueries.insert(Person("Willow", "Rosenberg"))
_ <- PersonQueries.insert(Person("Alexander", "Harris"))
_ <- console.putStrLn("Reading the trio")
_ <- console.putStrLn("Reading the trio").orDie
trio <- PersonQueries.list
} yield trio

Expand Down
6 changes: 3 additions & 3 deletions src/samples/scala/samples/doobie/LayeredAppStreaming.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ object LayeredAppStreaming extends zio.App {
/** Main code for the application. Results in a big ZIO depending on the AppEnv. */
def myApp(): ZIO[AppEnv, DbException, List[Person]] = {
val queries = for {
_ <- console.putStrLn("Creating the table")
_ <- console.putStrLn("Creating the table").orDie
_ <- PersonQueries.setup
_ <- console.putStrLn("Inserting the trio")
_ <- console.putStrLn("Inserting the trio").orDie
_ <- PersonQueries.insert(Person("Buffy", "Summers"))
_ <- PersonQueries.insert(Person("Willow", "Rosenberg"))
_ <- PersonQueries.insert(Person("Alexander", "Harris"))
_ <- PersonQueries.insert(Person("Rupert", "Giles")) // insert one more!
_ <- console.putStrLn("Reading the trio")
_ <- console.putStrLn("Reading the trio").orDie
trio <- {
val stream: ZStream[PersonQueries with Connection, DbException, Person] = PersonQueries.listStream.take(3)
stream.run(Sink.foldLeft(List[Person]())(_.prepended(_)))
Expand Down