简体   繁体   中英

How to implement DAO in Scala?

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM