This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val zioResult: ZIO[Any, Exception, PortfolioStatus] = | |
ApplicationService.getPortfolio(portfolioId).provide(env) | |
val runtime = new DefaultRuntime() {} | |
runtime.unsafeRun(zioResult) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LiveEnv | |
extends SlickAssetRepository | |
with SlickPortfolioAssetRepository | |
with LiveDatabaseProvider | |
val env = new LiveEnv() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ApplicationService { | |
def getPortfolio(portfolioId: PortfolioId): ZIO[AssetRepository with PortfolioAssetRepository, Exception, PortfolioStatus] = ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fromStreamingDBIO[T](dbio: StreamingDBIO[_, T]): ZIO[DatabaseProvider, Throwable, ZStream[Any, Throwable, T]] = | |
for { | |
db <- ZIO.accessM[DatabaseProvider](_.databaseProvider.db) | |
r <- ZIO.effect(db.stream(dbio).toStream()) | |
} yield r |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fromDBIO[R](dbio: DBIO[R]): ZIO[DatabaseProvider, Throwable, R] = | |
for { | |
db <- ZIO.accessM[DatabaseProvider](_.databaseProvider.db) | |
r <- ZIO.fromFuture(ec => db.run(dbio)) | |
} yield r |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
result <- ZIO.fromFuture(ec => db.run(dbio)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.run(action) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db <- ZIO.accessM[DatabaseProvider](_.databaseProvider.db) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait PortfolioAssetRepository { | |
def portfolioAssetRepository: PortfolioAssetRepository.Service | |
} | |
object PortfolioAssetRepository { | |
trait Service { | |
def add(name: String, price: BigDecimal): IO[RepositoryException, AssetId] | |
def getById(id: AssetId): IO[RepositoryException, Option[Asset]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait LiveDatabaseProvider extends DatabaseProvider { | |
override val databaseProvider = new DatabaseProvider.Service { | |
override val db = ZIO.effectTotal(Database.forURL(url = "jdbc:h2:prod")) | |
} | |
} |
NewerOlder