Skip to content

Commit

Permalink
Refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
balanka committed Jul 28, 2023
1 parent 7e04aaa commit 8b437bf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 2 additions & 2 deletions jdbc/src/main/scala/zio/sql/SqlDriverLiveModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ trait SqlDriverLiveModule { self: Jdbc =>
ZIO.attemptBlocking {
val statement = conn.createStatement()
delete.map(delete_ => statement.addBatch(renderDelete(delete_)))
statement.executeBatch().foldLeft(0) { case (acc, el) => acc + el }
statement.executeBatch().sum
}.refineToOrDie[Exception]

def update(update: Update[_]): IO[Exception, Int] =
Expand All @@ -65,7 +65,7 @@ trait SqlDriverLiveModule { self: Jdbc =>
ZIO.attemptBlocking {
val statement = conn.createStatement()
update.map(update_ => statement.addBatch(renderUpdate(update_)))
statement.executeBatch().foldLeft(0) { case (acc, el) => acc + el }
statement.executeBatch().sum
}.refineToOrDie[Exception]

def read[A](read: Read[A]): Stream[Exception, A] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ object TransactionSpec extends PostgresRunnableSpec with DbSchema {
test("Transaction failed and no row was inserted updated or deleted") {
val deleteQuery = deleteFrom(customers).where(verified === false)
val id1 = UUID.randomUUID()
// val id2 = UUID.randomUUID()

val c1 = Customer(
id1,
Expand All @@ -110,11 +109,10 @@ object TransactionSpec extends PostgresRunnableSpec with DbSchema {

val batchResult = for {
deleted <- deleteQuery.run
// inserted <- insertStmt.run
_ <- ZIO.fail(insertStmt.run).exit
updated <- updateStmt.run

} yield deleted + updated // + inserted
} yield deleted + updated

val result = (for {
tx <- transact(batchResult)
Expand Down

0 comments on commit 8b437bf

Please sign in to comment.