PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/app/src/main/scala/com/foursquare/muddlsample/app/MuddlApp.scala

https://github.com/jorgeortiz85/muddl-sample
Scala | 36 lines | 23 code | 7 blank | 6 comment | 0 complexity | b4cea164a24b671ee976cd21737abb2d MD5 | raw file
  1. package com.foursquare.muddlsample.app
  2. import com.foursquare.muddlsample.db.DatabaseConnections
  3. import com.foursquare.muddlsample.decorators.NiceVenue
  4. import com.foursquare.muddlsample.schema.Checkin
  5. import com.foursquare.muddlsample.serialization.{MongoSerializer, StrictMongoDeserializer}
  6. import com.mongodb.casbah.Imports._
  7. /**
  8. * An example app that initializes serializers, deserialiers, database connections, and databases,
  9. * and uses them to make some simple queries.
  10. */
  11. object MuddlApp {
  12. def main(args: Array[String]): Unit = {
  13. val deserializer = new StrictMongoDeserializer
  14. val serializer = new MongoSerializer
  15. val connections = new DatabaseConnections
  16. val databases = new MuddlDatabases(connections, deserializer, serializer)
  17. // There's weird data in the staging venue db with empty venues
  18. // which blow up on deserialization, so we'll avoid them
  19. val nonEmptyVenues = MongoDBObject("userid" -> MongoDBObject("$exists" -> true))
  20. val venues: Seq[NiceVenue] = databases.venues.find(nonEmptyVenues, 10)
  21. val checkins: Seq[Checkin] = databases.checkins.find(MongoDBObject(), 10)
  22. val venue = venues(0)
  23. venue.venuename // Look ma', no .value!
  24. venue.addressString // A derived field (from NiceVenue)
  25. val mutableVenue = venues(0).mutable
  26. mutableVenue.twitterName = Some("twitterhandle") // Settings a field
  27. ()
  28. }
  29. }