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