Skip to content

Instantly share code, notes, and snippets.

@stevef
Created September 3, 2013 20:51
Show Gist options
  • Save stevef/6429393 to your computer and use it in GitHub Desktop.
Save stevef/6429393 to your computer and use it in GitHub Desktop.
object InjuryTester {
implicit val dateRW = new BSONReader[BSONDateTime,Date] with BSONWriter[Date,BSONDateTime] {
def read(bson: BSONDateTime): Date = new Date(bson.value)
def write(date: Date): BSONDateTime = BSONDateTime(date.getTime)
}
implicit val pijHandler = Macros.handler[PlayerInjury]
implicit val ijHandler = Macros.handler[Injury2]
val driver = new MongoDriver
lazy val connection = driver.connection(Seq("localhost"))
lazy val db = connection("sport195-test")
def findAll = {
val x: Future[List[Injury2]] = db.collection("injuries").find(BSONDocument()).cursor[Injury2].toList
val ret: Future[List[PlayerInjury]] = x.map(injLst => injLst.map(inj => inj.players.getOrElse(Seq())).flatten)
ret
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment