-
Notifications
You must be signed in to change notification settings - Fork 32
Upgrading to doobie 1.0.0-RC1 (and Cats-Effect 3) #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a82a477
1f3ecf9
904e8dc
ba303e8
63690d3
51f0077
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,16 +4,13 @@ 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 zio.blocking.Blocking | ||
| import zio.interop.catz._ | ||
| import zio.stream.ZStream | ||
| import zio.stream.interop.fs2z._ | ||
| import zio.{Has, Tag, Task, ZIO, ZLayer} | ||
|
|
||
| import java.sql.{Connection => JdbcConnection} | ||
|
|
||
|
|
||
| /** TranzactIO module for Doobie. */ | ||
| package object doobie extends Wrapper { | ||
| override final type Connection = Has[Transactor[Task]] | ||
|
|
@@ -35,7 +32,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 */ | ||
|
|
@@ -47,17 +44,20 @@ package object doobie extends Wrapper { | |
| private[tranzactio] override implicit val connectionTag: Tag[Connection] = doobie.connectionTag | ||
|
|
||
| /** 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 => | ||
| val connect = (c: JdbcConnection) => Resource.pure[Task, JdbcConnection](c) | ||
| val interp = KleisliInterpreter[Task](b).ConnectionInterpreter | ||
| val tran = Transactor(connection, connect, interp, Strategy.void) | ||
| Has(tran) | ||
| } | ||
| final def connectionFromJdbc(env: TranzactioEnv, connection: JdbcConnection): ZIO[Any, Nothing, Connection] = { | ||
| ZIO.runtime[TranzactioEnv].flatMap { implicit r: zio.Runtime[TranzactioEnv] => | ||
| ZIO.succeed[Connection] { | ||
| val connect = (c: JdbcConnection) => Resource.pure[Task, JdbcConnection](c) | ||
| val interp = KleisliInterpreter[Task].ConnectionInterpreter | ||
| val tran = Transactor(connection, connect, interp, Strategy.void) | ||
| Has(tran) | ||
| } | ||
| }.provide(env) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PawelJ-PL In your code, you used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I can't remember, what I used |
||
| } | ||
|
|
||
| /** Creates a Database Layer which requires an existing ConnectionSource. */ | ||
| final def fromConnectionSource: ZLayer[ConnectionSource with Blocking, Nothing, Database] = | ||
| ZLayer.fromFunction { env: ConnectionSource with Blocking => | ||
| final def fromConnectionSource: ZLayer[ConnectionSource with TranzactioEnv, Nothing, Database] = | ||
| ZLayer.fromFunction { env: ConnectionSource with TranzactioEnv => | ||
| new DatabaseServiceBase[Connection](env.get[ConnectionSource.Service]) with Database.Service { | ||
| override final def connectionFromJdbc(connection: JdbcConnection): ZIO[Any, Nothing, Connection] = | ||
| self.connectionFromJdbc(env, connection) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| package io.github.gaelrenoux | ||
|
|
||
| import zio.Has | ||
| import zio.blocking.Blocking | ||
| import zio.clock.Clock | ||
|
|
||
| package object tranzactio { | ||
|
|
||
| type ConnectionSource = Has[ConnectionSource.Service] | ||
|
|
||
| type TranzactioEnv = Blocking with Clock | ||
|
|
||
| } |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hmemcpy I'm using
succeedinstead ofeffectTotalhere, because I don't think there's any effecting code going under the hood here. Am I missing something ?