8000 GitHub - eozel44/zio-rdms-transaction-management
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

eozel44/zio-rdms-transaction-management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Functional Transaction Management

Build transactions in purely functional way. With zio, doobie & postgres.

dependencies:

val zio         = "1.0.11"
val doobie      = "1.0.0-RC2"
val catsInterop = "3.1.1.0"
val postgres    = "42.3.5"
val hikari      = "4.0.3"
val zioLogging  = "0.5.10"
val circe       = "0.14.1"
val circeEnum   = "1.7.0"
val pureConfig  = "0.17.0"   

code:

override def signupUser(user: User, role: Role): IO[AppError, User] = {

  val tranzactIO = for {
    id   <- userRepo.createIO(user)
    _    <- userRoleRepo.createUserRoleIO(new UserRole(id, role))
    user <- userRepo.getIO(id)
  } yield user

  tranzactIO.transact(tx).orDie.flatMap {
    case Some(item) => ZIO.succeed(item)
    case None       => ZIO.fail(AppDaoError("signup error"))
  }

}

run:

  • execute scripts in resources/migration

  • sbt run

keywords:

zio, doobie, postgres, transaction

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0