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]] }
We will have three dao
packages: ProductDao
, ImageDao
, and ReviewDao
. Each dao
will be able to perform an operation, but over a different MySQL table...