15

I would like to implement DAO in Scala as follows:

trait DAO[PK,-T,-Q] {

   // T is a "value object", PK is a primary key, and Q is query parameters.

   def create(t:T):Unit
   def update(t:T):Unit
   def remove(pk:PK):Unit
   def find(query:Q):Seq[T]
}

Does it make sense ? Doesn't it look "too Java" ? How would you design/implement DAO in Scala ?

Michael
  • 10,185
  • 12
  • 59
  • 110
  • 1
    It depends upon the "heart" of what a DAO should be -- which is a very subjective topic ;-) –  Mar 19 '11 at 16:34
  • What do you want to achieve? Being ORM agnostic or implementing Active Record pattern? If you want to implement Active Record there are already ORMs that do so... – Rafa de Castro Mar 21 '11 at 12:05
  • Depending on what you are looking to do Lift provides a ful featured ORM so you wont have to roll out your own – AdamH Apr 01 '11 at 12:47

1 Answers1

4

I think Scala allows more direct and straightforward work with SQL databases than Java'ish DAO.

You may want to check out http://squeryl.org/ and other frameworks mentioned in this great answer: https://stackoverflow.com/questions/1362748/wanted-good-examples-of-scala-database-persistence/2318935#2318935

Community
  • 1
  • 1
Sasha O
  • 3,710
  • 2
  • 35
  • 45
  • Really appreciate the link to that other answer. Very helpful, thank you! – Brian Topping Apr 07 '13 at 22:06
  • 1
    For anyone stumbling on this like me, the linked post can be found at the [internet archive](http://web.archive.org/web/20141006104858/http://stackoverflow.com/questions/1362748/looking-for-a-comparison-of-scala-persistence-frameworks/2318935). – Rumpel Jul 04 '16 at 18:08