PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/scala/wtf/scala/e13/lecture/SalatExamples.scala

https://bitbucket.org/Tolsi/scala-school-2018-2
Scala | 39 lines | 23 code | 16 blank | 0 comment | 0 complexity | 825a36172220e19ae3dcb2a625e1655f MD5 | raw file
  1. package wtf.scala.e13.lecture
  2. import com.github.fakemongo.Fongo
  3. import com.mongodb.casbah.Imports._
  4. import com.mongodb.casbah.MongoCollection
  5. import salat.dao.{SalatDAO, SalatMongoCursor}
  6. import salat.global._
  7. object SalatExamples extends App {
  8. val fongo = new Fongo("jff")
  9. class EntityDAO extends SalatDAO[Entity, String](collection = new MongoCollection(fongo.getDB("test").getCollection("test")))
  10. val dao = new EntityDAO
  11. val entity: Option[Entity] = dao.findOneById("333")
  12. val queryResult: SalatMongoCursor[Entity] = dao.find(MongoDBObject("params.x" -> 15))
  13. val res: List[Entity] = queryResult.toList
  14. queryResult.close()
  15. val maybeId: Option[String] = dao.insert(Entity("4", Param(4, List(4, 5, 6))))
  16. val ids: List[Option[String]] = dao.insert(List(Entity("5", Param(5, List(1))),
  17. Entity("6", Param(6, List.empty))))
  18. val saveResult: WriteResult = dao.save(Entity("5", Param(1, List(1))))
  19. val removeByIdResult = dao.removeById("4")
  20. val removeByQueryResult = dao.remove(MongoDBObject("_id" -> "5"))
  21. val removeEntityResult = dao.remove(Entity("6", Param(6, List.empty)))
  22. val updateResult: WriteResult = dao.update(MongoDBObject("_id" -> "4"), $set("params.x" -> 18), upsert = false)
  23. }