Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement DAO in Scala?

Tags:

scala

dao

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 ?

like image 887
Michael Avatar asked Mar 19 '11 16:03

Michael


1 Answers

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

like image 114
Sasha O Avatar answered Oct 01 '22 20:10

Sasha O