Skip to content

Instantly share code, notes, and snippets.

Avatar
🎈

Jakub Czuchnowski jczuchnowski

🎈
View GitHub Profile
View zioAkkaSlickPost1_13.scala
val zioResult: ZIO[Any, Exception, PortfolioStatus] =
ApplicationService.getPortfolio(portfolioId).provide(env)
val runtime = new DefaultRuntime() {}
runtime.unsafeRun(zioResult)
View zioAkkaSlickPost1_12.scala
class LiveEnv
extends SlickAssetRepository
with SlickPortfolioAssetRepository
with LiveDatabaseProvider
val env = new LiveEnv()
View zioAkkaSlickPost1_11.scala
object ApplicationService {
def getPortfolio(portfolioId: PortfolioId): ZIO[AssetRepository with PortfolioAssetRepository, Exception, PortfolioStatus] = ...
}
View zioAkkaSlickPost1_10.scala
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
View zioAkkaSlickPost1_9.scala
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
View zioAkkaSlickPost1_6.scala
db <- ZIO.accessM[DatabaseProvider](_.databaseProvider.db)
View zioAkkaSlickPost1_5.scala
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]]
View zioAkkaSlickPost1_4.scala
trait LiveDatabaseProvider extends DatabaseProvider {
override val databaseProvider = new DatabaseProvider.Service {
override val db = ZIO.effectTotal(Database.forURL(url = "jdbc:h2:prod"))
}
}