From c716c6e6bb9b9c9f1097dfe3eebf7d528d72d68e Mon Sep 17 00:00:00 2001 From: takapi327 Date: Thu, 2 Jan 2025 16:00:28 +0900 Subject: [PATCH 1/3] Update DBIO --- .../src/main/scala/ldbc/dsl/DBIO.scala | 197 +++++++++++++----- 1 file changed, 148 insertions(+), 49 deletions(-) diff --git a/module/ldbc-dsl/src/main/scala/ldbc/dsl/DBIO.scala b/module/ldbc-dsl/src/main/scala/ldbc/dsl/DBIO.scala index 074f5948d..f01ea4ec3 100644 --- a/module/ldbc-dsl/src/main/scala/ldbc/dsl/DBIO.scala +++ b/module/ldbc-dsl/src/main/scala/ldbc/dsl/DBIO.scala @@ -6,7 +6,7 @@ package ldbc.dsl -import cats.{ Functor, Monad, MonadError } +import cats.* import cats.syntax.all.* import cats.effect.* @@ -24,100 +24,199 @@ import ldbc.dsl.logging.* * @tparam T * The result type of the query */ -trait DBIO[F[_]: Temporal, T]: +trait DBIO[F[_], T]: - private[ldbc] def execute(connection: Connection[F])(using logHandler: LogHandler[F]): F[T] + /** + * The function that actually executes the query. + * + * @param connection + * The connection to the database + * @param logHandler + * The log handler + * @return + * The result of the query + */ + def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[T] /** * Functions for managing the processing of connections in a read-only manner. */ - def readOnly(connection: Connection[F])(using LogHandler[F]): F[T] = - connection.setReadOnly(true) *> execute(connection) <* connection.setReadOnly(false) + def readOnly(connection: Connection[F])(using LogHandler[F]): F[T] /** * Functions to manage the processing of connections for writing. */ - def commit(connection: Connection[F])(using LogHandler[F]): F[T] = - connection.setReadOnly(false) *> connection.setAutoCommit(true) *> execute(connection) + def commit(connection: Connection[F])(using LogHandler[F]): F[T] /** * Functions to manage the processing of connections, always rolling back. */ - def rollback(connection: Connection[F])(using LogHandler[F]): F[T] = - connection.setReadOnly(false) *> connection.setAutoCommit(false) *> execute(connection) <* connection - .rollback() <* connection.setAutoCommit(true) + def rollback(connection: Connection[F])(using LogHandler[F]): F[T] /** * Functions to manage the processing of connections in a transaction. */ - def transaction(connection: Connection[F])(using LogHandler[F]): F[T] = - val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection) - - val release = (connection: Connection[F], exitCase: ExitCase) => - (exitCase match - case ExitCase.Errored(_) | ExitCase.Canceled => connection.rollback() - case _ => connection.commit() - ) - *> connection.setAutoCommit(true) - - Resource - .makeCase(acquire)(release) - .use(execute) + def transaction(connection: Connection[F])(using LogHandler[F]): F[T] object DBIO: private[ldbc] case class Impl[F[_]: Temporal, T]( statement: String, params: List[Parameter], - run: Connection[F] => F[T] + func: Connection[F] => F[T] ) extends DBIO[F, T]: - private[ldbc] def execute(connection: Connection[F])(using logHandler: LogHandler[F]): F[T] = - run(connection) + override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[T] = + func(connection) .onError(ex => logHandler.run(LogEvent.ProcessingFailure(statement, params.map(_.value), ex))) <* logHandler.run(LogEvent.Success(statement, params.map(_.value))) - def pure[F[_]: Temporal, T](value: T): DBIO[F, T] = - new DBIO[F, T]: - override private[ldbc] def execute(connection: Connection[F])(using LogHandler[F]): F[T] = Monad[F].pure(value) - override def readOnly(connection: Connection[F])(using LogHandler[F]): F[T] = Monad[F].pure(value) - override def commit(connection: Connection[F])(using LogHandler[F]): F[T] = Monad[F].pure(value) - override def rollback(connection: Connection[F])(using LogHandler[F]): F[T] = Monad[F].pure(value) - override def transaction(connection: Connection[F])(using LogHandler[F]): F[T] = Monad[F].pure(value) + override def readOnly(connection: Connection[F])(using LogHandler[F]): F[T] = + connection.setReadOnly(true) *> run(connection) <* connection.setReadOnly(false) + + override def commit(connection: Connection[F])(using LogHandler[F]): F[T] = + connection.setReadOnly(false) *> connection.setAutoCommit(true) *> run(connection) + + override def rollback(connection: Connection[F])(using LogHandler[F]): F[T] = + connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection.rollback() <* connection.setAutoCommit(true) + + override def transaction(connection: Connection[F])(using LogHandler[F]): F[T] = + val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection) + + val release = (connection: Connection[F], exitCase: ExitCase) => + (exitCase match + case ExitCase.Errored(_) | ExitCase.Canceled => connection.rollback() + case _ => connection.commit() + ) + *> connection.setAutoCommit(true) - def raiseError[F[_]: Temporal, A](e: Throwable): DBIO[F, A] = + Resource + .makeCase(acquire)(release) + .use(run) + + def pure[F[_]: Monad, A](value: A): DBIO[F, A] = new DBIO[F, A]: - override private[ldbc] def execute(connection: Connection[F])(using LogHandler[F]): F[A] = - MonadError[F, Throwable].raiseError(e) + override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[A] = Monad[F].pure(value) + override def readOnly(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value) + override def commit(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value) + override def rollback(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value) + override def transaction(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value) - given [F[_]: Temporal]: Functor[[T] =>> DBIO[F, T]] with - override def map[A, B](fa: DBIO[F, A])(f: A => B): DBIO[F, B] = - new DBIO[F, B]: - override private[ldbc] def execute(connection: Connection[F])(using LogHandler[F]): F[B] = - fa.execute(connection).map(f) + def raiseError[F[_], A](e: Throwable)(using ev: MonadThrow[F]): DBIO[F, A] = + new DBIO[F, A]: + override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[A] = ev.raiseError(e) + override def readOnly(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e) + override def commit(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e) + override def rollback(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e) + override def transaction(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e) given [F[_]: Temporal]: MonadError[[T] =>> DBIO[F, T], Throwable] with override def pure[A](x: A): DBIO[F, A] = DBIO.pure(x) override def flatMap[A, B](fa: DBIO[F, A])(f: A => DBIO[F, B]): DBIO[F, B] = new DBIO[F, B]: - override private[ldbc] def execute(connection: Connection[F])(using LogHandler[F]): F[B] = - fa.execute(connection).flatMap(a => f(a).execute(connection)) + override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[B] = fa.run(connection).flatMap(a => f(a).run(connection)) + override def readOnly(connection: Connection[F])(using LogHandler[F]): F[B] = + connection.setReadOnly(true) *> run(connection) <* connection.setReadOnly(false) + override def commit(connection: Connection[F])(using LogHandler[F]): F[B] = + connection.setReadOnly(false) *> connection.setAutoCommit(true) *> run(connection) + override def rollback(connection: Connection[F])(using LogHandler[F]): F[B] = + connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection.rollback() <* connection.setAutoCommit(true) + override def transaction(connection: Connection[F])(using LogHandler[F]): F[B] = + val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection) + val release = (connection: Connection[F], exitCase: ExitCase) => + (exitCase match + case ExitCase.Errored(_) | ExitCase.Canceled => connection.rollback() + case _ => connection.commit() + ) + *> connection.setAutoCommit(true) + Resource + .makeCase(acquire)(release) + .use(run) override def tailRecM[A, B](a: A)(f: A => DBIO[F, Either[A, B]]): DBIO[F, B] = new DBIO[F, B]: - override private[ldbc] def execute(connection: Connection[F])(using logHandler: LogHandler[F]): F[B] = - MonadError[F, Throwable].tailRecM(a)(a => f(a).execute(connection)) + override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[B] = + Temporal[F].tailRecM(a)(a => f(a).run(connection)) + + override def readOnly(connection: Connection[F])(using LogHandler[F]): F[B] = + connection.setReadOnly(true) *> run(connection) <* connection.setReadOnly(false) + + override def commit(connection: Connection[F])(using LogHandler[F]): F[B] = + connection.setReadOnly(false) *> connection.setAutoCommit(true) *> run(connection) + + override def rollback(connection: Connection[F])(using LogHandler[F]): F[B] = + connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection.rollback() <* connection.setAutoCommit(true) + + override def transaction(connection: Connection[F])(using LogHandler[F]): F[B] = + val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection) + + val release = (connection: Connection[F], exitCase: ExitCase) => + (exitCase match + case ExitCase.Errored(_) | ExitCase.Canceled => connection.rollback() + case _ => connection.commit() + ) + *> connection.setAutoCommit(true) + + Resource + .makeCase(acquire)(release) + .use(run) override def ap[A, B](ff: DBIO[F, A => B])(fa: DBIO[F, A]): DBIO[F, B] = new DBIO[F, B]: - override private[ldbc] def execute(connection: Connection[F])(using logHandler: LogHandler[F]): F[B] = - (ff.execute(connection), fa.execute(connection)).mapN(_(_)) + override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[B] = + (ff.run(connection), fa.run(connection)).mapN(_(_)) + + override def readOnly(connection: Connection[F])(using LogHandler[F]): F[B] = + connection.setReadOnly(true) *> run(connection) <* connection.setReadOnly(false) + + override def commit(connection: Connection[F])(using LogHandler[F]): F[B] = + connection.setReadOnly(false) *> connection.setAutoCommit(true) *> run(connection) + + override def rollback(connection: Connection[F])(using LogHandler[F]): F[B] = + connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection.rollback() <* connection.setAutoCommit(true) + + override def transaction(connection: Connection[F])(using LogHandler[F]): F[B] = + val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection) + + val release = (connection: Connection[F], exitCase: ExitCase) => + (exitCase match + case ExitCase.Errored(_) | ExitCase.Canceled => connection.rollback() + case _ => connection.commit() + ) + *> connection.setAutoCommit(true) + + Resource + .makeCase(acquire)(release) + .use(run) override def raiseError[A](e: Throwable): DBIO[F, A] = DBIO.raiseError(e) override def handleErrorWith[A](fa: DBIO[F, A])(f: Throwable => DBIO[F, A]): DBIO[F, A] = new DBIO[F, A]: - override private[ldbc] def execute(connection: Connection[F])(using LogHandler[F]): F[A] = - fa.execute(connection).handleErrorWith(e => f(e).execute(connection)) + override def run(connection: Connection[F])(using LogHandler[F]): F[A] = + fa.run(connection).handleErrorWith(e => f(e).run(connection)) + + override def readOnly(connection: Connection[F])(using LogHandler[F]): F[A] = + connection.setReadOnly(true) *> run(connection) <* connection.setReadOnly(false) + + override def commit(connection: Connection[F])(using LogHandler[F]): F[A] = + connection.setReadOnly(false) *> connection.setAutoCommit(true) *> run(connection) + + override def rollback(connection: Connection[F])(using LogHandler[F]): F[A] = + connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection.rollback() <* connection.setAutoCommit(true) + + override def transaction(connection: Connection[F])(using LogHandler[F]): F[A] = + val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection) + + val release = (connection: Connection[F], exitCase: ExitCase) => + (exitCase match + case ExitCase.Errored(_) | ExitCase.Canceled => connection.rollback() + case _ => connection.commit() + ) + *> connection.setAutoCommit(true) + + Resource + .makeCase(acquire)(release) + .use(run) From a96c09d928d7ca9e90b0855e131340f93c53a4fb Mon Sep 17 00:00:00 2001 From: takapi327 Date: Thu, 2 Jan 2025 16:00:35 +0900 Subject: [PATCH 2/3] Fixed DBIO test --- tests/src/test/scala/ldbc/tests/DBIOTest.scala | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/src/test/scala/ldbc/tests/DBIOTest.scala b/tests/src/test/scala/ldbc/tests/DBIOTest.scala index 8787faffb..d3e2bbcbb 100644 --- a/tests/src/test/scala/ldbc/tests/DBIOTest.scala +++ b/tests/src/test/scala/ldbc/tests/DBIOTest.scala @@ -33,7 +33,7 @@ class DBIOTest extends CatsEffectSuite: val program = DBIO.pure[IO, Int](1) assertIO( connection.use { conn => - program.execute(conn) + program.run(conn) }, 1 ) @@ -45,7 +45,7 @@ class DBIOTest extends CatsEffectSuite: val program3 = program2.ap(program1) assertIO( connection.use { conn => - program3.execute(conn) + program3.run(conn) }, 2 ) @@ -56,7 +56,7 @@ class DBIOTest extends CatsEffectSuite: val program2 = program1.map(_ + 1) assertIO( connection.use { conn => - program2.execute(conn) + program2.run(conn) }, 2 ) @@ -67,7 +67,7 @@ class DBIOTest extends CatsEffectSuite: val program2 = program1.flatMap(n => DBIO.pure[IO, Int](n + 1)) assertIO( connection.use { conn => - program2.execute(conn) + program2.run(conn) }, 2 ) @@ -78,7 +78,7 @@ class DBIOTest extends CatsEffectSuite: val program2 = program1.tailRecM[DBIO, String](_.map(n => Right(n.toString))) assertIO( connection.use { conn => - program2.execute(conn) + program2.run(conn) }, "1" ) @@ -88,7 +88,7 @@ class DBIOTest extends CatsEffectSuite: val program = DBIO.raiseError[IO, Int](new Exception("error")) interceptMessageIO[Exception]("error")( connection.use { conn => - program.execute(conn) + program.run(conn) } ) } @@ -98,7 +98,7 @@ class DBIOTest extends CatsEffectSuite: val program2 = program1.handleErrorWith(e => DBIO.pure[IO, Int](0)) assertIO( connection.use { conn => - program2.execute(conn) + program2.run(conn) }, 0 ) @@ -108,7 +108,7 @@ class DBIOTest extends CatsEffectSuite: val program = DBIO.pure[IO, Int](1) assertIO( connection.use { conn => - program.attempt.execute(conn) + program.attempt.run(conn) }, Right(1) ) @@ -118,7 +118,7 @@ class DBIOTest extends CatsEffectSuite: val program: DBIO[Int] = DBIO.raiseError[IO, Int](new Exception("error")) assertIOBoolean( connection.use { conn => - program.attempt.execute(conn).map(_.isLeft) + program.attempt.run(conn).map(_.isLeft) } ) } From 772cef5ac48ed0602cdf3ca32f2fed440f069ae2 Mon Sep 17 00:00:00 2001 From: takapi327 Date: Thu, 2 Jan 2025 16:01:01 +0900 Subject: [PATCH 3/3] Action sbt scalafmtAll --- .../src/main/scala/ldbc/dsl/DBIO.scala | 60 ++++++++++--------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/module/ldbc-dsl/src/main/scala/ldbc/dsl/DBIO.scala b/module/ldbc-dsl/src/main/scala/ldbc/dsl/DBIO.scala index f01ea4ec3..213a913e1 100644 --- a/module/ldbc-dsl/src/main/scala/ldbc/dsl/DBIO.scala +++ b/module/ldbc-dsl/src/main/scala/ldbc/dsl/DBIO.scala @@ -63,7 +63,7 @@ object DBIO: private[ldbc] case class Impl[F[_]: Temporal, T]( statement: String, params: List[Parameter], - func: Connection[F] => F[T] + func: Connection[F] => F[T] ) extends DBIO[F, T]: override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[T] = @@ -78,7 +78,8 @@ object DBIO: connection.setReadOnly(false) *> connection.setAutoCommit(true) *> run(connection) override def rollback(connection: Connection[F])(using LogHandler[F]): F[T] = - connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection.rollback() <* connection.setAutoCommit(true) + connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection + .rollback() <* connection.setAutoCommit(true) override def transaction(connection: Connection[F])(using LogHandler[F]): F[T] = val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection) @@ -86,8 +87,8 @@ object DBIO: val release = (connection: Connection[F], exitCase: ExitCase) => (exitCase match case ExitCase.Errored(_) | ExitCase.Canceled => connection.rollback() - case _ => connection.commit() - ) + case _ => connection.commit() + ) *> connection.setAutoCommit(true) Resource @@ -96,39 +97,41 @@ object DBIO: def pure[F[_]: Monad, A](value: A): DBIO[F, A] = new DBIO[F, A]: - override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[A] = Monad[F].pure(value) - override def readOnly(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value) - override def commit(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value) - override def rollback(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value) - override def transaction(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value) + override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[A] = Monad[F].pure(value) + override def readOnly(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value) + override def commit(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value) + override def rollback(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value) + override def transaction(connection: Connection[F])(using LogHandler[F]): F[A] = Monad[F].pure(value) def raiseError[F[_], A](e: Throwable)(using ev: MonadThrow[F]): DBIO[F, A] = new DBIO[F, A]: - override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[A] = ev.raiseError(e) - override def readOnly(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e) - override def commit(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e) - override def rollback(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e) - override def transaction(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e) + override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[A] = ev.raiseError(e) + override def readOnly(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e) + override def commit(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e) + override def rollback(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e) + override def transaction(connection: Connection[F])(using LogHandler[F]): F[A] = ev.raiseError(e) given [F[_]: Temporal]: MonadError[[T] =>> DBIO[F, T], Throwable] with override def pure[A](x: A): DBIO[F, A] = DBIO.pure(x) override def flatMap[A, B](fa: DBIO[F, A])(f: A => DBIO[F, B]): DBIO[F, B] = new DBIO[F, B]: - override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[B] = fa.run(connection).flatMap(a => f(a).run(connection)) + override def run(connection: Connection[F])(using logHandler: LogHandler[F]): F[B] = + fa.run(connection).flatMap(a => f(a).run(connection)) override def readOnly(connection: Connection[F])(using LogHandler[F]): F[B] = connection.setReadOnly(true) *> run(connection) <* connection.setReadOnly(false) override def commit(connection: Connection[F])(using LogHandler[F]): F[B] = connection.setReadOnly(false) *> connection.setAutoCommit(true) *> run(connection) override def rollback(connection: Connection[F])(using LogHandler[F]): F[B] = - connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection.rollback() <* connection.setAutoCommit(true) + connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection + .rollback() <* connection.setAutoCommit(true) override def transaction(connection: Connection[F])(using LogHandler[F]): F[B] = val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection) val release = (connection: Connection[F], exitCase: ExitCase) => (exitCase match case ExitCase.Errored(_) | ExitCase.Canceled => connection.rollback() - case _ => connection.commit() - ) + case _ => connection.commit() + ) *> connection.setAutoCommit(true) Resource .makeCase(acquire)(release) @@ -146,7 +149,8 @@ object DBIO: connection.setReadOnly(false) *> connection.setAutoCommit(true) *> run(connection) override def rollback(connection: Connection[F])(using LogHandler[F]): F[B] = - connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection.rollback() <* connection.setAutoCommit(true) + connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection + .rollback() <* connection.setAutoCommit(true) override def transaction(connection: Connection[F])(using LogHandler[F]): F[B] = val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection) @@ -154,8 +158,8 @@ object DBIO: val release = (connection: Connection[F], exitCase: ExitCase) => (exitCase match case ExitCase.Errored(_) | ExitCase.Canceled => connection.rollback() - case _ => connection.commit() - ) + case _ => connection.commit() + ) *> connection.setAutoCommit(true) Resource @@ -174,7 +178,8 @@ object DBIO: connection.setReadOnly(false) *> connection.setAutoCommit(true) *> run(connection) override def rollback(connection: Connection[F])(using LogHandler[F]): F[B] = - connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection.rollback() <* connection.setAutoCommit(true) + connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection + .rollback() <* connection.setAutoCommit(true) override def transaction(connection: Connection[F])(using LogHandler[F]): F[B] = val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection) @@ -182,8 +187,8 @@ object DBIO: val release = (connection: Connection[F], exitCase: ExitCase) => (exitCase match case ExitCase.Errored(_) | ExitCase.Canceled => connection.rollback() - case _ => connection.commit() - ) + case _ => connection.commit() + ) *> connection.setAutoCommit(true) Resource @@ -205,7 +210,8 @@ object DBIO: connection.setReadOnly(false) *> connection.setAutoCommit(true) *> run(connection) override def rollback(connection: Connection[F])(using LogHandler[F]): F[A] = - connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection.rollback() <* connection.setAutoCommit(true) + connection.setReadOnly(false) *> connection.setAutoCommit(false) *> run(connection) <* connection + .rollback() <* connection.setAutoCommit(true) override def transaction(connection: Connection[F])(using LogHandler[F]): F[A] = val acquire = connection.setReadOnly(false) *> connection.setAutoCommit(false) *> Temporal[F].pure(connection) @@ -213,8 +219,8 @@ object DBIO: val release = (connection: Connection[F], exitCase: ExitCase) => (exitCase match case ExitCase.Errored(_) | ExitCase.Canceled => connection.rollback() - case _ => connection.commit() - ) + case _ => connection.commit() + ) *> connection.setAutoCommit(true) Resource