Steve Klabnik changelog.com/posts

rogue - A Lift/MongoDB query DSL from Foursquare

Foursquare just announced a really neat new framework: rogue. Foursquare uses Scala to power their website, along with the Lift framework. They’ve been pretty vocal about their usage of MongoDB as well. This project combines all of that together.

Here’s what they have to say about the motivations for developing rogue:

Unfortunately, we found [Lift’s ORM] querying support a bit too expressive — you can pass in a query object that doesn’t represent a valid query, or query against fields that aren’t part of the record. And in addition it isn’t very type-safe. You can ask for, say, all Venue records where mayor = “Bob”, and it happily executes that query for you, returning nothing, never informing you that the mayor field is not a String but a Long representing the ID of the user. Well, we thought we could use the Scala type system to prevent this from ever happening, and that’s what we set out to do.

So what’s it look like? Here’s an example that should be familliar to anyone who’s used Foursquare:

Checkin where (_.venueid eqs id)
  and (_.userid eqs mayor.id)
  and (_.cheat eqs false)
  and (_._id after sixtyDaysAgo) 
  select(_._id) fetch()

Pretty cool. This will actually use Scala’s static type system to make sure you aren’t doing something stupid. For example, it will make sure that venueid is an actual member of Checkin, and also that id is of the same type as venueid.

Foursquare has made sure to mention that contributions are very welcome, so if Scala is your thing, fork away!


Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00