Search⌘ K

Doobie

Explore how to implement a pure functional repository in Scala using Doobie. Understand how to write handcrafted SQL queries, leverage refined types, and use fs2.Stream for pure functional data streaming to build scalable and testable back-end HTTP services.

We'll cover the following...

Repository base

As we have already started using a tagless final approach, we will continue with it and define a base for our repository.

Scala
trait Repository[F[_]] {
def loadProduct(id: ProductId): F[Seq[(ProductId, LanguageCode, ProductName)]]
def loadProducts(): Stream[F, (ProductId, LanguageCode, ProductName)]
def saveProduct(p: Product): F[Int]
def updateProduct(p: Product): F[Int]
}

We are feeling braver now and are attempting to use proper refined types in our database functions. This is possible due to the usage of the doobie-refined module.

To be able to map the UUID data type ...