Skip to content

Instantly share code, notes, and snippets.

@rktoomey
Created April 6, 2012 19:00
Show Gist options
  • Save rktoomey/2322082 to your computer and use it in GitHub Desktop.
Save rktoomey/2322082 to your computer and use it in GitHub Desktop.
For Tom
salat:master:0.0.8-SNAPSHOT> project salat-core
[info] Set current project to salat-core (in build file:/home/rose/workspace/salat/)
salat-core:master:0.0.8-SNAPSHOT> test:console
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import com.novus.salat._
import com.novus.salat._
scala> import com.novus.salat.global._ // puts the default Salat context in scope
import com.novus.salat.global._
scala> import com.novus.salat.dao._
import com.novus.salat.dao._
scala> import com.mongodb.casbah.Imports._
import com.mongodb.casbah.Imports._
scala> class BasicDAO[ObjectType <: AnyRef, ID <: Any](collectionName: String)(implicit mot: Manifest[ObjectType], mid: Manifest[ID], ctx: Context) extends
| SalatDAO[ObjectType, ID](collection = MongoConnection()("rainbows")(collectionName))(mot, mid, ctx)
defined class BasicDAO
scala> import com.novus.salat.test.dao.Theta // gives us a model object from salat's test package
import com.novus.salat.test.dao.Theta
scala> object ThetaDAO extends BasicDAO[Theta, ObjectId](collectionName = "theta")
defined module ThetaDAO
scala> ThetaDAO.description
res5: String = SalatDAO[Theta,ObjectId](theta)
scala> ThetaDAO.collection.db
res6: com.mongodb.casbah.MongoDB = rainbows
scala> ThetaDAO.collection.name
res7: java.lang.String = theta
scala> val _id = new ObjectId
_id: org.bson.types.ObjectId = 4f7f3cd44cea623bedd7c7bb
scala> val t = Theta(_id, "test", "ing")
t: com.novus.salat.test.dao.Theta = Theta(4f7f3cd44cea623bedd7c7bb,test,ing)
scala> ThetaDAO.insert(t)
res8: Option[com.mongodb.casbah.Imports.ObjectId] = Some(4f7f3cd44cea623bedd7c7bb)
scala> ThetaDAO.findOneByID(_id)
res9: Option[com.novus.salat.test.dao.Theta] = Some(Theta(4f7f3cd44cea623bedd7c7bb,test,ing))
scala> ThetaDAO.save(t.copy(y = "ed"))
scala> ThetaDAO.findOneByID(_id)
res11: Option[com.novus.salat.test.dao.Theta] = Some(Theta(4f7f3cd44cea623bedd7c7bb,test,ed))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment