Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove generic Field[V, M] => QueryField[V, M] implicit

  • Loading branch information...
commit 86a16f92cd0c8f46f5be25a74c99a0d269aedfaa 1 parent a977603
@jorgeortiz85 jorgeortiz85 authored
View
8 rogue-core/src/main/scala/com/foursquare/rogue/Query.scala
@@ -162,19 +162,19 @@ case class BaseQuery[
* type signature of the returned query is updated so that the "MaybeOrdered" type parameter is
* now Ordered.
*/
- def orderAsc[V](field: M => QueryField[V, M])
+ def orderAsc[V](field: M => AbstractQueryField[V, _, M])
(implicit ev: Ord =:= Unordered): BaseQuery[M, R, Ordered, Sel, Lim, Sk, Or] =
this.copy(order = Some(MongoOrder(List((field(meta).field.name, true)))))
- def orderDesc[V](field: M => QueryField[V, M])
+ def orderDesc[V](field: M => AbstractQueryField[V, _, M])
(implicit ev: Ord =:= Unordered): BaseQuery[M, R, Ordered, Sel, Lim, Sk, Or] =
this.copy(order = Some(MongoOrder(List((field(meta).field.name, false)))))
- def andAsc[V](field: M => QueryField[V, M])
+ def andAsc[V](field: M => AbstractQueryField[V, _, M])
(implicit ev: Ord =:= Ordered): BaseQuery[M, R, Ordered, Sel, Lim, Sk, Or] =
this.copy(order = Some(MongoOrder((field(meta).field.name, true) :: order.get.terms)))
- def andDesc[V](field: M => QueryField[V, M])
+ def andDesc[V](field: M => AbstractQueryField[V, _, M])
(implicit ev: Ord =:= Ordered): BaseQuery[M, R, Ordered, Sel, Lim, Sk, Or] =
this.copy(order = Some(MongoOrder((field(meta).field.name, false) :: order.get.terms)))
View
5 rogue-core/src/main/scala/com/foursquare/rogue/QueryExecutor.scala
@@ -2,6 +2,7 @@
package com.foursquare.rogue
+import com.foursquare.field.Field
import com.foursquare.rogue.MongoHelpers.{MongoModify, MongoSelect}
import com.mongodb.{DBObject, ReadPreference, WriteConcern}
import scala.collection.mutable.ListBuffer
@@ -43,7 +44,7 @@ trait QueryExecutor[MB] {
](
query: AbstractQuery[M, _, _, Sel, Lim, Sk, _]
)(
- field: M => QueryField[V, M]
+ field: M => Field[V, M]
)(
implicit
// ev1: Sel =:= SelectedOne,
@@ -53,7 +54,7 @@ trait QueryExecutor[MB] {
if (optimizer.isEmptyQuery(query)) {
0L
} else {
- adapter.countDistinct(query, field(query.meta).field.name)
+ adapter.countDistinct(query, field(query.meta).name)
}
}
View
14 rogue-core/src/main/scala/com/foursquare/rogue/QueryField.scala
@@ -74,15 +74,15 @@ abstract class AbstractQueryField[V, DB, M](val field: Field[V, M]) {
def between(v1: V, v2: V) =
new BetweenQueryClause(field.name, valueToDB(v1), valueToDB(v2))
+
+ def exists(b: Boolean) = new ExistsQueryClause(field.name, b)
+
+ def hastype(t: MongoType.Value) = new TypeQueryClause(field.name, t)
}
class QueryField[V, M](field: Field[V, M])
extends AbstractQueryField[V, V, M](field) {
override def valueToDB(v: V) = v
-
- def exists(b: Boolean) = new ExistsQueryClause(field.name, b)
-
- def hastype(t: MongoType.Value) = new TypeQueryClause(field.name, t)
}
class CalendarQueryField[M](val field: Field[java.util.Calendar, M]) {
@@ -177,7 +177,11 @@ class ForeignObjectIdQueryField[M, T](
new NinQueryClause(field.name, QueryHelpers.validatedList(objs.map(getId)))
}
-class StringQueryField[M](val field: Field[String, M]) {
+class StringQueryField[M](override val field: Field[String, M])
+ extends AbstractQueryField[String, String, M](field) {
+
+ override def valueToDB(v: String): String = v
+
def startsWith(s: String): RegexQueryClause[PartialIndexScan] =
new RegexQueryClause[PartialIndexScan](field.name, PartialIndexScan, Pattern.compile("^" + Pattern.quote(s)))
View
64 rogue-core/src/main/scala/com/foursquare/rogue/Rogue.scala
@@ -7,6 +7,7 @@ import com.foursquare.field.{
OptionalField => ROptionalField,
RequiredField => RRequiredField}
import com.foursquare.rogue.MongoHelpers.{AndCondition, MongoModify}
+import com.mongodb.DBObject
import java.util.{Calendar, Date}
import net.liftweb.common.Box
import org.bson.types.ObjectId
@@ -51,46 +52,29 @@ trait Rogue {
}
// QueryField implicits
- implicit def rfieldToQueryField[M, F](f: RField[F, M]): QueryField[F, M] = new QueryField(f)
-
- implicit def rcalendarFieldToCalendarQueryField[M, F]
- (f: RField[java.util.Calendar, M]): CalendarQueryField[M] =
- new CalendarQueryField(f)
-
- implicit def rdoubleFieldtoNumericQueryField[M, F]
- (f: RField[Double, M]): NumericQueryField[Double, M] =
- new NumericQueryField(f)
-
- implicit def renumNameFieldToEnumNameQueryField[M, F <: Enumeration#Value]
- (f: RField[F, M]): EnumNameQueryField[M, F] =
- new EnumNameQueryField(f)
-
- implicit def renumerationListFieldToEnumerationListQueryField[M, F <: Enumeration#Value]
- (f: RField[List[F], M]): EnumerationListQueryField[F, M] =
- new EnumerationListQueryField[F, M](f)
-
- implicit def rintFieldtoNumericQueryField[M, F](f: RField[Int, M]): NumericQueryField[Int, M] =
- new NumericQueryField(f)
-
- implicit def rlatLongFieldToGeoQueryField[M](f: RField[LatLong, M]): GeoQueryField[M] =
- new GeoQueryField(f)
-
- implicit def rlistFieldToListQueryField[M, F](f: RField[List[F], M]): ListQueryField[F, M] =
- new ListQueryField[F, M](f)
-
- implicit def rlongFieldtoNumericQueryField[M](f: RField[Long, M]): NumericQueryField[Long, M] =
- new NumericQueryField(f)
-
- implicit def robjectIdFieldToObjectIdQueryField[M, F](f: RField[ObjectId, M])
- : ObjectIdQueryField[M] =
- new ObjectIdQueryField(f)
-
- implicit def rmapFieldToMapQueryField[M, F](f: RField[Map[String, F], M]): MapQueryField[F, M] =
- new MapQueryField[F, M](f)
-
- implicit def rstringFieldToStringQueryField[M](f: RField[String, M]): StringQueryField[M] =
- new StringQueryField(f)
-
+ // implicit def rfieldToQueryField[M, F](f: RField[F, M]): QueryField[F, M] = new QueryField(f)
+
+ implicit def rbooleanFieldtoQueryField[M](f: RField[Boolean, M]): QueryField[Boolean, M] = new QueryField(f)
+ implicit def rcharFieldtoQueryField[M](f: RField[Char, M]): QueryField[Char, M] = new QueryField(f)
+
+ implicit def rbyteFieldtoNumericQueryField[M](f: RField[Byte, M]): NumericQueryField[Byte, M] = new NumericQueryField(f)
+ implicit def rshortFieldtoNumericQueryField[M](f: RField[Short, M]): NumericQueryField[Short, M] = new NumericQueryField(f)
+ implicit def rintFieldtoNumericQueryField[M](f: RField[Int, M]): NumericQueryField[Int, M] = new NumericQueryField(f)
+ implicit def rlongFieldtoNumericQueryField[M](f: RField[Long, M]): NumericQueryField[Long, M] = new NumericQueryField(f)
+ implicit def rfloatFieldtoNumericQueryField[M](f: RField[Float, M]): NumericQueryField[Float, M] = new NumericQueryField(f)
+ implicit def rdoubleFieldtoNumericQueryField[M](f: RField[Double, M]): NumericQueryField[Double, M] = new NumericQueryField(f)
+
+ implicit def rstringFieldToStringQueryField[M](f: RField[String, M]): StringQueryField[M] = new StringQueryField(f)
+ implicit def robjectIdFieldToObjectIdQueryField[M](f: RField[ObjectId, M]): ObjectIdQueryField[M] = new ObjectIdQueryField(f)
+ implicit def rdateFieldToQueryField[M](f: RField[Date, M]): QueryField[Date, M] = new QueryField(f)
+ implicit def rcalendarFieldToCalendarQueryField[M](f: RField[Calendar, M]): CalendarQueryField[M] = new CalendarQueryField(f)
+ implicit def rdbobjectFieldToQueryField[M](f: RField[DBObject, M]): QueryField[DBObject, M] = new QueryField(f)
+
+ implicit def renumNameFieldToEnumNameQueryField[M, F <: Enumeration#Value](f: RField[F, M]): EnumNameQueryField[M, F] = new EnumNameQueryField(f)
+ implicit def renumerationListFieldToEnumerationListQueryField[M, F <: Enumeration#Value](f: RField[List[F], M]): EnumerationListQueryField[F, M] = new EnumerationListQueryField[F, M](f)
+ implicit def rlatLongFieldToGeoQueryField[M](f: RField[LatLong, M]): GeoQueryField[M] = new GeoQueryField(f)
+ implicit def rlistFieldToListQueryField[M, F](f: RField[List[F], M]): ListQueryField[F, M] = new ListQueryField[F, M](f)
+ implicit def rmapFieldToMapQueryField[M, F](f: RField[Map[String, F], M]): MapQueryField[F, M] = new MapQueryField[F, M](f)
/** ModifyField implicits
*
View
3  rogue-field/build.sbt
@@ -1 +1,4 @@
Seq(RogueBuild.defaultSettings: _*)
+
+// scaladoc kept erroring out. something about package objects. screw it.
+doc in Compile := file("none.txt")
View
5 rogue-lift/src/main/scala/com/foursquare/rogue/ExecutableQuery.scala
@@ -2,6 +2,7 @@ package com.foursquare.rogue
// Copyright 2012 Foursquare Labs Inc. All Rights Reserved.
+import com.foursquare.field.Field
import com.foursquare.rogue.MongoHelpers.MongoSelect
import com.mongodb.WriteConcern
@@ -30,9 +31,9 @@ case class ExecutableQuery[
* Returns the number of distinct values returned by a query. The query must not have
* limit or skip clauses.
*/
- def countDistinct[V](field: M => QueryField[V, _])
+ def countDistinct[V](field: M => Field[V, _])
(implicit ev1: Lim =:= Unlimited, ev2: Sk =:= Unskipped): Long =
- db.countDistinct(query)(field.asInstanceOf[M => QueryField[V, M]])
+ db.countDistinct(query)(field.asInstanceOf[M => Field[V, M]])
/**
* Checks if there are any records that match this query.
Please sign in to comment.
Something went wrong with that request. Please try again.