Doobie – functional database access

The database layer in our example is implemented with the Doobie library. Its official website describes it as a pure functional JDBC layer for Scala and Cats. It allows us to abstract existing JDBC functionality in a nice functional way. Let's show how this is done. The library can be found at https://tpolecat.github.io/doobie/. In the following examples, please assume the following imports to be in scope: 

import cats.effect.IOimport fs2.Streamimport doobie._import doobie.implicits._import doobie.util.transactor.Transactorimport cats.implicits._

We also need some model classes to persist, and for the purpose of the example, we'll keep the ADT as small as possible:

object Model {  type Inventory = Map

Get Learn Scala Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.