• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / atala-prism-building-blocks / 8479182462

29 Mar 2024 08:58AM UTC coverage: 31.807% (+0.4%) from 31.453%
8479182462

Pull #952

web-flow
Update docs/decisions/20240116-use-zio-failures-and-defects-effectively.md

Co-authored-by: Pete Vielhaber <peter.vielhaber@iohk.io>
Signed-off-by: bvoiturier <benjamin.voiturier@iohk.io>
Pull Request #952: docs(adr): ATL-6599 update ADR based on first implementation experience

4515 of 14195 relevant lines covered (31.81%)

0.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.5
/shared/src/main/scala/io/iohk/atala/shared/db/ContextAwareTask.scala
1
package io.iohk.atala.shared.db
2

3
import doobie.*
4
import doobie.postgres.implicits.*
5
import doobie.syntax.ConnectionIOOps
6
import doobie.util.transactor.Transactor
7
import io.iohk.atala.shared.models.WalletAccessContext
8
import io.iohk.atala.shared.models.WalletId
9
import zio.*
10
import zio.interop.catz.*
11

12
import java.util.UUID
13

14
trait ContextAware
15
type ContextAwareTask[T] = Task[T] with ContextAware
16

17
object Implicits {
18

×
19
  given walletIdGet: Get[WalletId] = Get[UUID].map(WalletId.fromUUID)
1✔
20
  given walletIdPut: Put[WalletId] = Put[UUID].contramap(_.toUUID)
21

22
  private val WalletIdVariableName = "app.current_wallet_id"
23

24
  extension [A](ma: ConnectionIO[A]) {
1✔
25
    def transactWithoutContext(xa: Transactor[ContextAwareTask]): Task[A] = {
×
26
      ConnectionIOOps(ma).transact(xa.asInstanceOf[Transactor[Task]])
27
    }
28

1✔
29
    def transactWallet(xa: Transactor[ContextAwareTask]): RIO[WalletAccessContext, A] = {
1✔
30
      def walletCxnIO(ctx: WalletAccessContext) = {
1✔
31
        for {
×
32
          _ <- doobie.free.connection.createStatement.map { statement =>
×
33
            statement.execute(s"SET LOCAL $WalletIdVariableName TO '${ctx.walletId}'")
34
          }
1✔
35
          result <- ma
36
        } yield result
37
      }
38

1✔
39
      for {
×
40
        ctx <- ZIO.service[WalletAccessContext]
×
41
        result <- ConnectionIOOps(walletCxnIO(ctx)).transact(xa.asInstanceOf[Transactor[Task]])
42
      } yield result
43
    }
44

45
  }
46

47
  extension [Int](ma: RIO[WalletAccessContext, Int]) {
1✔
48
    def ensureOneAffectedRowOrDie: URIO[WalletAccessContext, Unit] = ma.flatMap {
1✔
49
      case 1     => ZIO.unit
1✔
50
      case count => ZIO.fail(RuntimeException(s"Unexpected affected row count: $count"))
51
    }.orDie
52
  }
53

54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc