com.foursquare.rogue

Query

case class Query[M, R, +State](meta: M, collectionName: String, lim: Option[Int], sk: Option[Int], maxScan: Option[Int], comment: Option[String], hint: Option[ListMap[String, Any]], condition: AndCondition, order: Option[MongoOrder], select: Option[MongoSelect[M, R]], readPreference: Option[ReadPreference]) extends Product with Serializable

The definition of methods needed to build a query.

To construct a query, an instance of a query-builder needs to be created. That's done by using an implicit conversion from an instance of a meta-record. In code, the user writes a query by calling one of the query construction methods on an instance of the query-record meta-record instance. The implicit conversion will construct an appropriate query builder from the meta-record.

Query builders are parameterized using a collection of phantom types. For our purposes here, phantom types are types which are inferred by the type system, rather than being explicitly provided by users. The phantom types are inferred by the type system on the basis of what clauses are contained in the query. For example, if there's a ordering clause, that constrains the types so that the type system must infer a type parameter of type "Ordered". This use of phantom types allows the type system to prevent a range of query errors - for example, if two query clauses have incompatible ordering constraints, the type system will reject it.

The specific mechanics of the type inference process are based on implicit parameters. A type can only get inferred into an expression based on a parameter. But we don't want people to have to specify parameters explicitly - that would wreck the syntax. Instead, we use implicit parameters. The inference system will find an implicit parameter that is type compatible with what's used in the rest of the expression.

M

the record type being queried.

R
State

a phantom type which defines the state of the builder.

Linear Supertypes
Serializable, Serializable, Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Query
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AnyRef
  7. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Query(meta: M, collectionName: String, lim: Option[Int], sk: Option[Int], maxScan: Option[Int], comment: Option[String], hint: Option[ListMap[String, Any]], condition: AndCondition, order: Option[MongoOrder], select: Option[MongoSelect[M, R]], readPreference: Option[ReadPreference])

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. def allShards[S2](implicit ev: AddShardAware[State, _, S2]): Query[M, R, S2]

  7. def and[F](clause: (M) ⇒ QueryClause[F]): Query[M, R, State]

    Adds another and-connected clause to the query.

  8. def andAsc(field: (M) ⇒ AbstractQueryField[_, _, _, M])(implicit ev: <:<[State, Ordered]): Query[M, R, State]

  9. def andDesc(field: (M) ⇒ AbstractQueryField[_, _, _, M])(implicit ev: <:<[State, Ordered]): Query[M, R, State]

  10. def andOpt[V, F](opt: Option[V])(clause: (M, V) ⇒ QueryClause[F]): Query[M, R, State]

  11. def asDBObject: DBObject

  12. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  13. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  14. val collectionName: String

  15. def comment(c: String): Query[M, R, State]

  16. val comment: Option[String]

  17. val condition: AndCondition

  18. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  19. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  20. def findAndModify[F](clause: (M) ⇒ ModifyClause)(implicit ev1: Required[State, Unlimited with Unskipped], ev2: RequireShardKey[M, State]): FindAndModifyQuery[M, R]

  21. def findAndModifyOpt[V](opt: Option[V])(clause: (M, V) ⇒ ModifyClause)(implicit ev1: Required[State, Unlimited with Unskipped], ev2: RequireShardKey[M, State]): FindAndModifyQuery[M, R]

  22. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  23. def hint(index: MongoIndex[M]): Query[M, R, State]

  24. val hint: Option[ListMap[String, Any]]

  25. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  26. def iscan[F](clause: (M) ⇒ QueryClause[F]): Query[M, R, State]

    Adds an iscan clause to a query.

  27. def iscanOpt[V, F](opt: Option[V])(clause: (M, V) ⇒ QueryClause[F]): Query[M, R, State]

  28. val lim: Option[Int]

  29. def limit[S2](n: Int)(implicit ev: AddLimit[State, S2]): Query[M, R, S2]

    Places a limit on the size of the returned result.

    Places a limit on the size of the returned result.

    Like "or", this uses the Rogue phantom-type/implicit parameter mechanics. To call this method, the query must not yet have a limit clause attached. This is captured by the implicit parameter being constrained to be "Unlimited". After this is called, the type signature of the returned query is updated so that the "MaybeLimited" type parameter is now Limited.

  30. def limitOpt[S2](n: Option[Int])(implicit ev: AddLimit[State, S2]): Query[M, R, S2]

  31. def maxScan(max: Int): Query[M, R, State]

  32. val maxScan: Option[Int]

  33. val meta: M

  34. def modify(clause: (M) ⇒ ModifyClause)(implicit ev1: Required[State, Unselected with Unlimited with Unskipped], ev2: ShardingOk[M, State]): ModifyQuery[M, State]

  35. def modifyOpt[V](opt: Option[V])(clause: (M, V) ⇒ ModifyClause)(implicit ev1: Required[State, Unselected with Unlimited with Unskipped], ev2: ShardingOk[M, State]): ModifyQuery[M, State]

  36. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  37. def noop()(implicit ev1: Required[State, Unselected with Unlimited with Unskipped], ev2: ShardingOk[M, State]): ModifyQuery[M, State]

  38. def not[F](clause: (M) ⇒ QueryClause[F]): Query[M, R, State]

    Adds a negated clause to the query.

  39. final def notify(): Unit

    Definition Classes
    AnyRef
  40. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  41. def or[S2](subqueries: (Query[M, R, Ordered with Selected with Limited with Skipped with HasNoOrClause]) ⇒ Query[M, R, _]*)(implicit ev: AddOrClause[State, S2]): Query[M, R, S2]

    Chains an "or" subquery to the current query.

    Chains an "or" subquery to the current query.

    The use of the implicit parameter here is key to how the Rogue type checking mechanics work. In order to attach an "or" clause to a query, the query as it exists must not yet have an or-clause. So the implicit parameter, which carries the phantom type information, must be "HasNoOrClause" before this is called. After it's called, you can see that the "MaybeHasOrClause" type parameter is changed, and is now specifically bound to "HasOrClause", rather than to a type variable.

  42. val order: Option[MongoOrder]

  43. def orderAsc[S2](field: (M) ⇒ AbstractQueryField[_, _, _, M])(implicit ev: AddOrder[State, S2]): Query[M, R, S2]

    Like "or", this uses the Rogue phantom-type/implicit parameter mechanics.

    Like "or", this uses the Rogue phantom-type/implicit parameter mechanics. To call this method, the query must not yet have an ordering clause attached. This is captured by the implicit parameter being constrained to be "Unordered". After this is called, the type signature of the returned query is updated so that the "MaybeOrdered" type parameter is now Ordered.

  44. def orderDesc[S2](field: (M) ⇒ AbstractQueryField[_, _, _, M])(implicit ev: AddOrder[State, S2]): Query[M, R, S2]

  45. def orderNaturalAsc[V, S2](implicit ev: AddOrder[State, S2]): Query[M, R, S2]

    Natural ordering.

    Natural ordering. TODO: doesn't make sense in conjunction with ordering on any other fields. enforce w/ phantom types?

  46. def orderNaturalDesc[V, S2](implicit ev: AddOrder[State, S2]): Query[M, R, S2]

  47. def raw(f: (BasicDBObjectBuilder) ⇒ Unit): Query[M, R, State]

  48. val readPreference: Option[ReadPreference]

  49. def scan[F](clause: (M) ⇒ QueryClause[F]): Query[M, R, State]

    Adds a scan clause to a query.

  50. def scanOpt[V, F](opt: Option[V])(clause: (M, V) ⇒ QueryClause[F]): Query[M, R, State]

  51. def select[F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], f3: (M) ⇒ SelectField[F3, M], f4: (M) ⇒ SelectField[F4, M], f5: (M) ⇒ SelectField[F5, M], f6: (M) ⇒ SelectField[F6, M], f7: (M) ⇒ SelectField[F7, M], f8: (M) ⇒ SelectField[F8, M], f9: (M) ⇒ SelectField[F9, M], f10: (M) ⇒ SelectField[F10, M])(implicit ev: AddSelect[State, S2, _]): Query[M, (F1, F2, F3, F4, F5, F6, F7, F8, F9, F10), S2]

  52. def select[F1, F2, F3, F4, F5, F6, F7, F8, F9, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], f3: (M) ⇒ SelectField[F3, M], f4: (M) ⇒ SelectField[F4, M], f5: (M) ⇒ SelectField[F5, M], f6: (M) ⇒ SelectField[F6, M], f7: (M) ⇒ SelectField[F7, M], f8: (M) ⇒ SelectField[F8, M], f9: (M) ⇒ SelectField[F9, M])(implicit ev: AddSelect[State, S2, _]): Query[M, (F1, F2, F3, F4, F5, F6, F7, F8, F9), S2]

  53. def select[F1, F2, F3, F4, F5, F6, F7, F8, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], f3: (M) ⇒ SelectField[F3, M], f4: (M) ⇒ SelectField[F4, M], f5: (M) ⇒ SelectField[F5, M], f6: (M) ⇒ SelectField[F6, M], f7: (M) ⇒ SelectField[F7, M], f8: (M) ⇒ SelectField[F8, M])(implicit ev: AddSelect[State, S2, _]): Query[M, (F1, F2, F3, F4, F5, F6, F7, F8), S2]

  54. def select[F1, F2, F3, F4, F5, F6, F7, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], f3: (M) ⇒ SelectField[F3, M], f4: (M) ⇒ SelectField[F4, M], f5: (M) ⇒ SelectField[F5, M], f6: (M) ⇒ SelectField[F6, M], f7: (M) ⇒ SelectField[F7, M])(implicit ev: AddSelect[State, S2, _]): Query[M, (F1, F2, F3, F4, F5, F6, F7), S2]

  55. def select[F1, F2, F3, F4, F5, F6, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], f3: (M) ⇒ SelectField[F3, M], f4: (M) ⇒ SelectField[F4, M], f5: (M) ⇒ SelectField[F5, M], f6: (M) ⇒ SelectField[F6, M])(implicit ev: AddSelect[State, S2, _]): Query[M, (F1, F2, F3, F4, F5, F6), S2]

  56. def select[F1, F2, F3, F4, F5, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], f3: (M) ⇒ SelectField[F3, M], f4: (M) ⇒ SelectField[F4, M], f5: (M) ⇒ SelectField[F5, M])(implicit ev: AddSelect[State, S2, _]): Query[M, (F1, F2, F3, F4, F5), S2]

  57. def select[F1, F2, F3, F4, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], f3: (M) ⇒ SelectField[F3, M], f4: (M) ⇒ SelectField[F4, M])(implicit ev: AddSelect[State, S2, _]): Query[M, (F1, F2, F3, F4), S2]

  58. def select[F1, F2, F3, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], f3: (M) ⇒ SelectField[F3, M])(implicit ev: AddSelect[State, S2, _]): Query[M, (F1, F2, F3), S2]

  59. def select[F1, F2, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M])(implicit ev: AddSelect[State, S2, _]): Query[M, (F1, F2), S2]

  60. def select[F1, S2](f1: (M) ⇒ SelectField[F1, M])(implicit ev: AddSelect[State, _, S2]): Query[M, F1, S2]

  61. val select: Option[MongoSelect[M, R]]

  62. def selectCase[F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, CC, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], f3: (M) ⇒ SelectField[F3, M], f4: (M) ⇒ SelectField[F4, M], f5: (M) ⇒ SelectField[F5, M], f6: (M) ⇒ SelectField[F6, M], f7: (M) ⇒ SelectField[F7, M], f8: (M) ⇒ SelectField[F8, M], f9: (M) ⇒ SelectField[F9, M], f10: (M) ⇒ SelectField[F10, M], create: (F1, F2, F3, F4, F5, F6, F7, F8, F9, F10) ⇒ CC)(implicit ev: AddSelect[State, S2, _]): Query[M, CC, S2]

  63. def selectCase[F1, F2, F3, F4, F5, F6, F7, F8, F9, CC, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], f3: (M) ⇒ SelectField[F3, M], f4: (M) ⇒ SelectField[F4, M], f5: (M) ⇒ SelectField[F5, M], f6: (M) ⇒ SelectField[F6, M], f7: (M) ⇒ SelectField[F7, M], f8: (M) ⇒ SelectField[F8, M], f9: (M) ⇒ SelectField[F9, M], create: (F1, F2, F3, F4, F5, F6, F7, F8, F9) ⇒ CC)(implicit ev: AddSelect[State, S2, _]): Query[M, CC, S2]

  64. def selectCase[F1, F2, F3, F4, F5, F6, F7, F8, CC, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], f3: (M) ⇒ SelectField[F3, M], f4: (M) ⇒ SelectField[F4, M], f5: (M) ⇒ SelectField[F5, M], f6: (M) ⇒ SelectField[F6, M], f7: (M) ⇒ SelectField[F7, M], f8: (M) ⇒ SelectField[F8, M], create: (F1, F2, F3, F4, F5, F6, F7, F8) ⇒ CC)(implicit ev: AddSelect[State, S2, _]): Query[M, CC, S2]

  65. def selectCase[F1, F2, F3, F4, F5, F6, F7, CC, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], f3: (M) ⇒ SelectField[F3, M], f4: (M) ⇒ SelectField[F4, M], f5: (M) ⇒ SelectField[F5, M], f6: (M) ⇒ SelectField[F6, M], f7: (M) ⇒ SelectField[F7, M], create: (F1, F2, F3, F4, F5, F6, F7) ⇒ CC)(implicit ev: AddSelect[State, S2, _]): Query[M, CC, S2]

  66. def selectCase[F1, F2, F3, F4, F5, F6, CC, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], f3: (M) ⇒ SelectField[F3, M], f4: (M) ⇒ SelectField[F4, M], f5: (M) ⇒ SelectField[F5, M], f6: (M) ⇒ SelectField[F6, M], create: (F1, F2, F3, F4, F5, F6) ⇒ CC)(implicit ev: AddSelect[State, S2, _]): Query[M, CC, S2]

  67. def selectCase[F1, F2, F3, F4, F5, CC, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], f3: (M) ⇒ SelectField[F3, M], f4: (M) ⇒ SelectField[F4, M], f5: (M) ⇒ SelectField[F5, M], create: (F1, F2, F3, F4, F5) ⇒ CC)(implicit ev: AddSelect[State, S2, _]): Query[M, CC, S2]

  68. def selectCase[F1, F2, F3, F4, CC, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], f3: (M) ⇒ SelectField[F3, M], f4: (M) ⇒ SelectField[F4, M], create: (F1, F2, F3, F4) ⇒ CC)(implicit ev: AddSelect[State, S2, _]): Query[M, CC, S2]

  69. def selectCase[F1, F2, F3, CC, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], f3: (M) ⇒ SelectField[F3, M], create: (F1, F2, F3) ⇒ CC)(implicit ev: AddSelect[State, S2, _]): Query[M, CC, S2]

  70. def selectCase[F1, F2, CC, S2](f1: (M) ⇒ SelectField[F1, M], f2: (M) ⇒ SelectField[F2, M], create: (F1, F2) ⇒ CC)(implicit ev: AddSelect[State, S2, _]): Query[M, CC, S2]

  71. def selectCase[F1, CC, S2](f1: (M) ⇒ SelectField[F1, M], create: (F1) ⇒ CC)(implicit ev: AddSelect[State, _, S2]): Query[M, CC, S2]

  72. def setReadPreference(r: ReadPreference): Query[M, R, State]

    Set a flag to indicate whether this query should hit primaries or secondaries.

    Set a flag to indicate whether this query should hit primaries or secondaries. This only really makes sense if you're using replica sets. If this field is unspecified, rogue will leave the option untouched, so you'll use secondaries or not depending on how you configure the mongo java driver. Also, this only works if you're doing a query -- findAndModify, updates, and deletes always go to the primaries.

    For more info, see http://www.mongodb.org/display/DOCS/slaveOk

  73. def signature(): String

  74. val sk: Option[Int]

  75. def skip[S2](n: Int)(implicit ev: AddSkip[State, S2]): Query[M, R, S2]

    Adds a skip to the query.

    Adds a skip to the query.

    Like or, this uses the Rogue phantom-type/implicit parameter mechanics. To call this method, the query must not yet have a skip clause attached. This is captured by the implicit parameter being constrained to be Unskipped. After this is called, the type signature of the returned query is updated so that the MaybeSkipped type parameter is now Skipped.

  76. def skipOpt[S2](n: Option[Int])(implicit ev: AddSkip[State, S2]): Query[M, R, S2]

  77. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  78. def toString(): String

    Definition Classes
    Query → AnyRef → Any
  79. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  80. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  81. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  82. def where[F](clause: (M) ⇒ QueryClause[F]): Query[M, R, State]

    Adds a where clause to a query.

  83. def whereOpt[V, F](opt: Option[V])(clause: (M, V) ⇒ QueryClause[F]): Query[M, R, State]

  84. def withShardKey[F, S2](clause: (M) ⇒ QueryClause[F] with ShardKeyClause)(implicit ev: AddShardAware[State, S2, _]): Query[M, R, S2]

    Adds an eqs clause specifying the shard key.

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped