O'Reilly logo

Building Applications with Scala by Diego Pacheco

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

FPM Mapping

The next step is to create FPM mapping between our Scala code and MySQL tables under ReactiveWebStore/app, we will create a new package called dao. DAO stands for Database Access Object (DAO), and is a well-known OO pattern. So we will create some DAO classes here. First we will define a base trait, which will define the behavior and code capability for each of our dao packages.

We will start with BaseDao.scala:

 package dao import slick.lifted.TableQuery import scala.concurrent.Future /** * Defines base dao structure every dao should have. */ trait BaseDao[T] { def toTable():TableQuery[_] def findAll():Future[Seq[T]] def remove(id:Long):Future[Int] def insert(o:T):Future[Unit] def update(o:T):Future[Unit] def findById(id:Long):Future[Option[T]] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required