• Stars
    star
    489
  • Rank 89,990 (Top 2 %)
  • Language
    Scala
  • License
    Other
  • Created almost 14 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

MOVED - The project is still under development but this page is deprecated.

NOTICE - This project has moved.

It is now part of Foursquare's open source monorepo Fsq.io and all future work will be published there.

The project lives on but this Github repo is deprecated.

Rogue

Rogue is a type-safe internal Scala DSL for constructing and executing find and modify commands against MongoDB in the Lift web framework. It is fully expressive with respect to the basic options provided by MongoDB's native query language, but in a type-safe manner, building on the record types specified in your Lift models. An example:

Venue.where(_.mayor eqs 1234).and(_.tags contains "Thai").fetch(10)

The type system enforces the following constraints:

  • the fields must actually belong to the record (e.g., mayor is a field on the Venue record)
  • the field type must match the operand type (e.g., mayor is an IntField)
  • the operator must make sense for the field type (e.g., categories is a MongoListField[String])

In addition, the type system ensures that certain builder methods are only used in certain circumstances. For example, take this more complex query:

Venue.where(_.closed eqs false).orderAsc(_.popularity).limit(10).modify(_.closed setTo true).updateMulti

This query purportedly finds the 10 least popular open venues and closes them. However, MongoDB does not (currently) allow you to specify limits on modify queries, so Rogue won't let you either. The above will generate a compiler error.

Constructions like this:

def myMayorships = Venue.where(_.mayor eqs 1234).limit(5)
...
myMayorships.fetch(10)

will also not compile, here because a limit is being specified twice. Other similar constraints are in place to prevent you from accidentally doing things you don't want to do anyway.

Installation

Because Rogue is designed to work with several versions of lift-mongodb-record, you'll want to declare your dependency on Rogue as intransitive and declare an explicit dependency on the version of Lift you want to target. In sbt, that would look like the following:

val rogueField      = "com.foursquare" %% "rogue-field"         % "2.5.0" intransitive()
val rogueCore       = "com.foursquare" %% "rogue-core"          % "2.5.1" intransitive()
val rogueLift       = "com.foursquare" %% "rogue-lift"          % "2.5.1" intransitive()
val rogueIndex      = "com.foursquare" %% "rogue-index"         % "2.5.1" intransitive()
val liftMongoRecord = "net.liftweb"    %% "lift-mongodb-record" % "2.6"

Rogue 2.5.x requires Lift 2.6-RC1 or later. For support for earlier versions of Lift, use Rogue 2.4.0 or earlier. If you encounter problems using Rogue with other versions of Lift, please let us know.

Join the rogue-users google group for help, bug reports, feature requests, and general discussion on Rogue.

Setup

Define your record classes in Lift like you would normally (see TestModels.scala for examples).

Then anywhere you want to use rogue queries against these records, import the following:

import com.foursquare.rogue.LiftRogue._

See EndToEndTest.scala for a complete working example.

More Examples

QueryTest.scala contains sample Records and examples of every kind of query supported by Rogue. It also indicates what each query translates to in MongoDB's JSON query language. It's a good place to look when getting started using Rogue.

NB: The examples in QueryTest only construct query objects; none are actually executed. Once you have a query object, the following operations are supported (listed here because they are not demonstrated in QueryTest):

For "find" query objects

val query = Venue.where(_.venuename eqs "Starbucks")
query.count()
query.countDistinct(_.mayor)
query.fetch()
query.fetch(n)
query.get()     // equivalent to query.fetch(1).headOption
query.exists()  // equivalent to query.fetch(1).size > 0
query.foreach{v: Venue => ... }
query.paginate(pageSize)
query.fetchBatch(pageSize){vs: List[Venue] => ...}
query.bulkDelete_!!(WriteConcern.SAFE)
query.findAndDeleteOne()
query.explain()
query.iterate(handler)
query.iterateBatch(batchSize, handler)

For "modify" query objects

val modify = query.modify(_.mayor_count inc 1)
modify.updateMulti()
modify.updateOne()
modify.upsertOne()

for "findAndModify" query objects

val modify = query.where(_.legacyid eqs 222).findAndModify(_.closed setTo true)
modify.updateOne(returnNew = ...)
modify.upsertOne(returnNew = ...)

Releases

The latest release is 2.5.1. See the changelog for more details.

Dependencies

lift-mongodb-record, mongodb, joda-time, junit. These dependencies are managed by the build system.

Maintainers

Rogue was initially developed by Foursquare Labs for internal use -- nearly all of the MongoDB queries in foursquare's code base go through this library. The current maintainers are:

Contributions welcome!

More Repositories

1

twofishes

MOVED - The project is still under development but this page is deprecated.
Scala
433
star
2

FSNetworking

foursquare iOS networking library
Objective-C
384
star
3

fsqio

A monorepo that holds all of Foursquare's opensource projects
Scala
254
star
4

quattroshapes

Makefile
231
star
5

FSQCollectionViewAlignedLayout

FSQCollectionViewAlignedLayout is a generic collection view layout designed to be very flexible and configurable. It's goal is to save its users from having to write their own custom layout classes every time UICollectionViewFlowLayout is not appropriate for their view.
Objective-C
176
star
6

fongo

faked out in-memory mongo for java
Java
150
star
7

foursquare-android-oauth

Foursquare native authentication makes it easier for your app's users to connect with Foursquare. Unlike web-based OAuth, native authentication re-uses the Foursquare app's user credentials, saving users the hassle of re-logging in to Foursquare within your app.
Java
134
star
8

foursquare-palmpre

A webOS app (Mojo Framework)
JavaScript
105
star
9

foursquare-ios-oauth

Foursquare native authentication makes it easier for your app's users to connect with Foursquare. Unlike web-based OAuth, native authentication re-uses the Foursquare app's user credentials, saving users the hassle of re-logging in to Foursquare within your app.
Objective-C
104
star
10

slashem

A rogue-like DSL for querying SOLR
Scala
103
star
11

FSQLocationBroker

A centralized location manager for your app.
Objective-C
94
star
12

oozie-web

A more pretty, more usable web dashboard for Apache Oozie, written in Scala.
JavaScript
74
star
13

foursquare-fhttp

MOVED - The project is still under development but this page is deprecated.
Scala
44
star
14

FSQCellManifest

A UITableView and UICollectionView delegate and datasource that provides a simpler unified interface for describing your sections and cells.
Objective-C
43
star
15

quiver

An HFile-backed Key-Value Server
Go
42
star
16

hackathon

foursquare hackathonsâ„¢
40
star
17

spindle

MOVED - The project is still under development but this page is deprecated.
Scala
39
star
18

mongo-hdfs-export

Scala
31
star
19

foursquare-app-framework

Framework for building Connected Apps
Python
31
star
20

react-foursquare

Foursquare Library for React
JavaScript
25
star
21

es-scorer-plugin

Plugin to do our scoring in ES
Scala
24
star
22

sites-to-markdown

convert google sites html to markdown
Java
23
star
23

FSQRoutes

URL routing framework for iOS
Objective-C
21
star
24

fsq-studio-sdk-examples

Foursquare Studio is a platform to visualize, unify, enrich, and analyze spatial data on a planetary scale.
Jupyter Notebook
19
star
25

qgis-plugin

Foursquare Studio plugin for QGIS
Python
19
star
26

datasource-plugin-clouderamanager

Cloudera Manager datasource for Grafana 3.x
JavaScript
19
star
27

twitter-util-async

scala-async support for twitter util library
Scala
15
star
28

Place-API-Postman-Collection

Postman collection that contains almost all the sample Foursquare Places API calls.
14
star
29

foursquair

An Adobe AIR desktop client for foursquare
ActionScript
14
star
30

placepicker-sdk-sample

An SDK to help developers add a place picker to their app and also quickly access the Foursquare place that their user is at.
Java
11
star
31

wait

wait gem: executes a block until there's a result
Ruby
10
star
32

hoursparser.js

dumb but useful hours extractor from free-text entry
JavaScript
9
star
33

h3-presto

Presto bindings for H3, a hierarchical hexagonal geospatial indexing system
Java
8
star
34

gitshed

git versioning of large binary files outside the repo.
Python
8
star
35

shapefile-geo

Java
8
star
36

pilgrim-sdk-react-native

React native wrapper for the Pilgrim SDK
Java
7
star
37

fsgo

Reusable libraries for building Go services
Go
7
star
38

FSQMessageForwarder

An Obj-C message forwarder class, for when you don't have access to the source of the sending object.
Objective-C
6
star
39

merchant-app

JavaScript
5
star
40

source_code_analysis

Utilities to analyze, lint and rewrite source code in various languages.
Python
5
star
41

gohfile

5
star
42

exceptionator

MOVED - The project is still under development but this page is deprecated.
JavaScript
5
star
43

foursquare-places

framework agnostic wrapper for foursquare's APIs
JavaScript
5
star
44

android-map-utils

A collection of 3rd party map utility classes
4
star
45

cc-shapefiles

Scala
3
star
46

pilgrim-unity-package

Unity package which enables easy integration with Pilgrim SDK
Objective-C
3
star
47

foursquareapi-csharp

C#
3
star
48

foursquare.github.io

Foursquare open source portal
HTML
2
star
49

movementsdk-ios-spm

Movement SDK for iOS - Swift Package Manager
Swift
2
star
50

foursquare-places-api-samples

Developer Examples for using Foursquare products
HTML
2
star
51

simple-macros

MOVED - The project is still under development but this page is deprecated.
Scala
2
star
52

FSQComponents

Objective-C
2
star
53

RNPilgrimSample

Pilgrim sample app using React Native
Java
2
star
54

json-traverser

Scala
1
star
55

hackmidwest

This repo contains everything developers need to get started at Hack Midwest!
1
star
56

MovementSdk-CocoaPods-Beta

Private CocoaPods Spec repo for the Movement SDK
Ruby
1
star
57

finagle-dual

Support thrift and HTTP on same port with Finagle
Scala
1
star
58

movement-sdk-react-native

React native wrapper for the Movement SDK
Objective-C
1
star
59

pilgrimsdk-adobe-extension

The pilgrim adobe extension
Kotlin
1
star
60

public-model-resources

Jupyter Notebook
1
star
61

mobbing-interview-python

Used by the Security & Quality Team for interviews
1
star
62

RNMovementSample

Movement SDK sample app using React Native
Java
1
star
63

Pilgrim-CocoaPods-Beta

Public cocoapods spec repo for Pilgrim SDK beta builds
Ruby
1
star
64

pilgrim-ios-spm

Pilgrim SDK for iOS - Swift Package Manager
Swift
1
star
65

alertmon

Foursquare's homegrown production alerting platform
Python
1
star
66

commons-old

Temporary duplicate of foursquare/commons (a fork of twitter/commons) while we restructure things.
Java
1
star