-
-
Save Jacoby6000/de6e9ffa559b7ed43f02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models.dao | |
import scala.concurrent.ExecutionContext | |
import scala.concurrent.Future | |
import play.api.Play.current | |
import play.modules.reactivemongo.ReactiveMongoPlugin | |
import reactivemongo.api.collections.default.BSONCollection | |
import reactivemongo.bson.BSONDocument | |
import reactivemongo.bson.BSONDocumentIdentity | |
import reactivemongo.bson.BSONDocumentReader | |
import reactivemongo.bson.BSONDocumentWriter | |
import reactivemongo.core.commands.LastError | |
trait MongoDAO[T] { | |
implicit val ec: ExecutionContext | |
implicit val reader: BSONDocumentReader[T] | |
val collectionName: String | |
def db = ReactiveMongoPlugin.db | |
def collection = db[BSONCollection](collectionName) | |
def insert[T](document: T)(implicit writer: BSONDocumentWriter[T]): Future[LastError] = { | |
collection.insert(document) | |
} | |
def findAll(implicit reader: BSONDocumentReader[T]): Future[List[T]] = { | |
collection.find(BSONDocument()).cursor[T].collect[List]() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment