Skip to Content
Mastering Functional Programming
book

Mastering Functional Programming

by Anatolii Kmetiuk
August 2018
Intermediate to advanced
380 pages
10h 2m
English
Packt Publishing
Content preview from Mastering Functional Programming

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Functional Programming

Learning Functional Programming

Jack Widman

Publisher Resources

ISBN: 9781788620796Supplemental Content