PageRenderTime 23ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/core/src/main/scala/db/DefRepo.scala

http://github.com/ornicar/scalex
Scala | 31 lines | 23 code | 8 blank | 0 comment | 1 complexity | 82a53d764d19a9a603eb5f67ee26f4ad MD5 | raw file
  1. package scalex
  2. package db
  3. import model.Def
  4. import com.mongodb.casbah.Imports._
  5. import com.mongodb.casbah.MongoCollection
  6. import com.novus.salat._
  7. import com.novus.salat.global._
  8. import com.novus.salat.dao._
  9. class DefRepo(collection: MongoCollection) extends SalatDAO[Def, ObjectId](collection) {
  10. def batchInsert(objs: List[Def]) { collection insert (objs map _grater.asDBObject) }
  11. def byIds(ids: Seq[String]): List[Def] = {
  12. val defs = find("_id" $in ids) toList
  13. val sorted = ids map { id => defs.find(_.id == id) }
  14. sorted.flatten.toList
  15. }
  16. def removePack(pack: String) {
  17. collection remove MongoDBObject("pack" -> pack)
  18. }
  19. def findAll: List[Def] = find(MongoDBObject()).toList
  20. def findByDeclaration(dec: String) = findOne(MongoDBObject(
  21. "declaration" -> dec
  22. ))
  23. }