Database layer

A database layer is implemented in terms of the Doobie library. Each entity has a separate Scala file, where there is a singleton object, which has all of the methods that we need for the purposes of this application. For example, let's take a look at the API that the customer object exposes:

object customer extends CustomerDbHelpers {  def create(c: Customer): IO[Int] = ???  def findByName(name: String): IO[Option[Customer]] = ???  def list: IO[List[Customer]] = ???  def get(id: Int): IO[Customer] = ???  def update(c: Customer): IO[Int] = ???  def delete(id: Int): IO[Int] = ???}trait CustomerDbHelpers {  val selectCustomerSql = fr"select * from customer"  // to be explained further in the chapter}

So, we have several database access ...

Get Mastering Functional 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.