1

I'm used to write SQL or use simple database interaction tool like Active Record. Slick has this really elaborate functional database connection concept, and I want to learn more, although just beginning.

I used play-slick and some people told me to use trait DAO (which has something to do with Scala Cake Pattern). Also it is said DAO is used to place common functions that would otherwise have been written inside object xxx.

Now I'm trying to write a function in DAO that can query data out of database based on which object is calling it, for example:

trait DAO extends Apple with Orange {
   val apples = new Apples //Apples is a class extending Table trait inside Apple trait
   val oranges = new Oranges //same above

   def get() = {...//some mysterious implementation}
}

Object Apples extends DAO { //companion object of Apples class
    ....
}//same for Object Orange

So now I can just call Apples.get() and get all the apples in the database, but if I call Oranges.get(), I can get all oranges in the database. Is there a way to do this?

windweller
  • 2,365
  • 5
  • 33
  • 56

0 Answers0