Last active
August 29, 2015 14:20
-
-
Save shirishp/476f5374d3e9129196c6 to your computer and use it in GitHub Desktop.
JSONCollection
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
object CollectionImplicits { | |
implicit class RichJSONCollection(val self: JSONCollection) extends AnyVal { | |
def insertWithTimestamp(document: JsObject) = { | |
self.insert(document ++ Json.obj("updatedAt" -> new java.util.Date().getTime)) | |
} | |
} | |
} | |
// Usage | |
case class Board(name: String, sections: List[Section]) | |
object JsonFormats { | |
implicit val boardFormat = Json.format[Board] | |
implicit val boardReads = Json.reads[Board] | |
} | |
private lazy val collection: JSONCollection = database.collection[JSONCollection]("boards") | |
def create(board: Board) = collection.insert(board) // now, board is writable to JSON, but I want above insertWithTimestamp to work here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment