Created
June 14, 2012 16:13
-
-
Save rktoomey/2931238 to your computer and use it in GitHub Desktop.
Gossips
This file contains hidden or 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 model | |
import com.novus.salat.global._ | |
import com.novus.salat.annotations._ | |
import com.novus.salat.dao.SalatDAO | |
case class Gossip(@Key("_id") id: org.bson.types.ObjectId, | |
title: String, | |
link: String = "", | |
description: String, | |
permalink: String, | |
image: String, | |
date: String) | |
object GossipDAO extends SalatDAO[Gossip, ObjectId](collection = MongoConnection()("salat_db")("gossip_items")) |
This file contains hidden or 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
scala> import com.novus.salat._ | |
import com.novus.salat._ | |
scala> import com.novus.salat.global._ | |
import com.novus.salat.global._ | |
scala> import model.{ Gossip, GossipDAO } | |
import model.{Gossip, GossipDAO} | |
scala> import org.joda.time.format.ISODateTimeFormat | |
import org.joda.time.format.ISODateTimeFormat | |
scala> import com.mongodb.casbah.Imports._ | |
import com.mongodb.casbah.Imports._ | |
scala> com.mongodb.casbah.commons.conversions.scala.RegisterConversionHelpers() | |
scala> com.mongodb.casbah.commons.conversions.scala.RegisterJodaTimeConversionHelpers() | |
scala> GossipDAO.description | |
res2: String = SalatDAO[Gossip,ObjectId](gossip_items) | |
scala> GossipDAO.collection.count | |
res3: Long = 0 | |
scala> val _id = new org.bson.types.ObjectId("4f7f4ae4251735803a942b2c") | |
_id: org.bson.types.ObjectId = 4f7f4ae4251735803a942b2c | |
scala> val dbo = MongoDBObject("_id" -> _id, "category" -> "", "title" -> "sample title", "permalink" -> "http->//", "description" -> "Sample Description", "image" -> "http->//", "modificationDate" -> ISODateTimeFormat.dateTime.parseDateTime("2012-04-06T19:58:28.448Z"), "date" -> "Fri, 06 Apr 2012 18->02->00 GMT") | |
dbo: com.mongodb.DBObject = { "_id" : { "$oid" : "4f7f4ae4251735803a942b2c"} , "category" : "" , "title" : "sample title" , "permalink" : "http->//" , "description" : "Sample Description" , "image" : "http->//" , "modificationDate" : { "$date" : "2012-04-06T19:58:28.448Z"} , "date" : "Fri, 06 Apr 2012 18->02->00 GMT"} | |
scala> val g = grater[Gossip].asObject(dbo) | |
g: model.Gossip = Gossip(4f7f4ae4251735803a942b2c,sample title,,Sample Description,http->//,http->//,Fri, 06 Apr 2012 18->02->00 GMT) | |
scala> GossipDAO.collection.insert(dbo) | |
res4: com.mongodb.WriteResult = N/A | |
scala> GossipDAO.collection.count | |
res5: Long = 1 | |
scala> GossipDAO.findOne(MongoDBObject("_id" -> _id)) | |
res6: Option[model.Gossip] = Some(Gossip(4f7f4ae4251735803a942b2c,sample title,,Sample Description,http->//,http->//,Fri, 06 Apr 2012 18->02->00 GMT)) | |
scala> val startDate = ISODateTimeFormat.dateTime.parseDateTime("2012-04-01T19:58:28.448Z") | |
startDate: org.joda.time.DateTime = 2012-04-01T15:58:28.448-04:00 | |
scala> val gossips = GossipDAO.find(ref = MongoDBObject("modificationDate" -> MongoDBObject("$gte" -> startDate))).toList | |
gossips: List[com.novus.salat.test.dao.Gossip] = List(Gossip(4f7f4ae4251735803a942b2c,sample title,,Sample Description,http->//,http->//,Fri, 06 Apr 2012 18->02->00 GMT)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment