Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* upgrading to sbt 0.11.2

* adding missing junit dependency (something depends on junit, not sure what)
* enforce  $pushAll & $pullAll arguments can be converted to Iterable at compile time
* switched to a type class (AsQueryParam) for queryparams to avoid code duplication
  • Loading branch information...
commit 784de6e23a6d75bbfcb47264cd01d9cb76f50c79 1 parent 5d0d430
@teigen teigen authored
View
30 casbah-query/src/main/scala/BarewordOperators.scala
@@ -68,8 +68,6 @@ class NestedBarewordListOperator(oper: String) {
}
-
-
/**
* Aggregation object for Bareword Operators.
* Bareword operators stand on their own - they lack the requirement for an LValue.
@@ -180,15 +178,8 @@ trait PushOp extends PushOpBase {
}
trait PushAllOpBase extends BarewordQueryOperator {
- protected def _pushAll[A <: Any: Manifest](args: (String, A)*): DBObject =
- if (manifest[A] <:< manifest[Iterable[_]])
- apply("$pushAll")(args.map(z => z._1 -> z._2.asInstanceOf[Iterable[_]]): _*)
- else if (manifest[A] <:< manifest[Product])
- apply("$pushAll")(args.map(z => z._1 -> z._2.asInstanceOf[Product].productIterator.toIterable): _*)
- else if (manifest[A].erasure.isArray)
- apply("$pushAll")(args.map(z => z._1 -> z._2.asInstanceOf[Array[_]].toIterable): _*)
- else
- throw new IllegalArgumentException("$pushAll may only be invoked with a (String, A) where String is the field name and A is an Iterable or Product/Tuple of values (got %s).".format(manifest[A]))
+ protected def _pushAll[A : AsIterable](args: (String, A)*): DBObject =
+ apply("$pushAll")(args.map(z => z._1 -> AsIterable[A].asIterable(z._2)) :_*)
}
/*
@@ -203,7 +194,7 @@ trait PushAllOpBase extends BarewordQueryOperator {
* @see http://www.mongodb.org/display/DOCS/Updating#Updating-%24pushAll
*/
trait PushAllOp extends PushAllOpBase {
- def $pushAll[A <: Any: Manifest](args: (String, A)*): DBObject = _pushAll(args: _*)
+ def $pushAll[A : AsIterable](args: (String, A)*): DBObject = _pushAll(args: _*)
}
trait AddToSetOpBase extends BarewordQueryOperator {
@@ -304,17 +295,8 @@ trait PullOp extends PullOpBase {
}
trait PullAllOpBase extends BarewordQueryOperator {
- protected def _pullAll[A <: Any: Manifest](args: (String, A)*): DBObject =
- if (manifest[A] <:< manifest[Iterable[_]])
- apply("$pullAll")(args.map(z => z._1 -> z._2.asInstanceOf[Iterable[_]]): _*)
- else if (manifest[A] <:< manifest[Product])
- apply("$pullAll")(args.map(z => z._1 -> z._2.asInstanceOf[Product].productIterator.toIterable): _*)
- else if (manifest[A].erasure.isArray)
- apply("$pullAll")(args.map(z => z._1 -> z._2.asInstanceOf[Array[_]].toIterable): _*)
- else
- throw new IllegalArgumentException("$pullAll may only be invoked with a (String, A) where String is the field name and A is an Iterable or Product/Tuple of values (got %s).".format(manifest[A]))
-
-
+ protected def _pullAll[A : AsIterable](args: (String, A)*): DBObject =
+ apply("$pullAll")(args.map(z => z._1 -> AsIterable[A].asIterable(z._2)): _*)
}
/*
@@ -329,7 +311,7 @@ trait PullAllOpBase extends BarewordQueryOperator {
* @see http://www.mongodb.org/display/DOCS/Updating#Updating-%24pullAll
*/
trait PullAllOp extends PullAllOpBase {
- def $pullAll[A <: Any: Manifest](args: (String, A)*): DBObject = _pullAll(args: _*)
+ def $pullAll[A : AsIterable](args: (String, A)*): DBObject = _pullAll(args: _*)
}
trait AndOpBase {
View
228 casbah-query/src/main/scala/CoreOperators.scala
@@ -153,37 +153,8 @@ trait QueryOperator extends Logging {
*/
trait NotEqualsOp extends QueryOperator {
private val oper = "$ne"
-
- def $ne(target: String) = op(oper, target)
- def $ne(target: DBObject) = op(oper, target)
- def $ne(target: DBRef) = op(oper, target)
- def $ne(target: ObjectId) = op(oper, target)
- def $ne(target: Boolean) = op(oper, target)
- def $ne(target: Array[_]) = op(oper, target.toList)
- def $ne(target: Tuple1[_]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple2[_, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple3[_, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple4[_, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple5[_, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple6[_, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple7[_, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple8[_, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple9[_, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple10[_, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple11[_, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $ne(target: Iterable[_]) = op(oper, target.toList)
- def $ne[T: ValidDateOrNumericType](target: T) = op(oper, target)
+
+ def $ne[A : AsQueryParam](a:A) = op(oper, AsQueryParam[A].asQueryParam(a))
}
/**
@@ -198,34 +169,8 @@ trait NotEqualsOp extends QueryOperator {
*/
trait LessThanOp extends QueryOperator {
private val oper = "$lt"
-
- def $lt(target: String) = op(oper, target)
- def $lt(target: DBObject) = op(oper, target)
- def $lt(target: Array[_]) = op(oper, target.toList)
- def $lt(target: Tuple1[_]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple2[_, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple3[_, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple4[_, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple5[_, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple6[_, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple7[_, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple8[_, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple9[_, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple10[_, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple11[_, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lt(target: Iterable[_]) = op(oper, target.toList)
- def $lt[T: ValidDateOrNumericType](target: T) = op(oper, target)
+
+ def $lt[A : AsQueryParam](a: A) = op(oper, AsQueryParam[A].asQueryParam(a))
}
/**
@@ -239,34 +184,8 @@ trait LessThanOp extends QueryOperator {
*/
trait LessThanEqualOp extends QueryOperator {
private val oper = "$lte"
-
- def $lte(target: String) = op(oper, target)
- def $lte(target: DBObject) = op(oper, target)
- def $lte(target: Array[_]) = op(oper, target.toList)
- def $lte(target: Tuple1[_]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple2[_, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple3[_, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple4[_, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple5[_, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple6[_, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple7[_, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple8[_, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple9[_, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple10[_, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple11[_, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $lte(target: Iterable[_]) = op(oper, target.toList)
- def $lte[T: ValidDateOrNumericType](target: T) = op(oper, target)
+
+ def $lte[A : AsQueryParam](a: A) = op(oper, AsQueryParam[A].asQueryParam(a))
}
/**
@@ -280,34 +199,8 @@ trait LessThanEqualOp extends QueryOperator {
*/
trait GreaterThanOp extends QueryOperator {
private val oper = "$gt"
-
- def $gt(target: String) = op(oper, target)
- def $gt(target: DBObject) = op(oper, target)
- def $gt(target: Array[_]) = op(oper, target.toList)
- def $gt(target: Tuple1[_]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple2[_, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple3[_, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple4[_, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple5[_, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple6[_, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple7[_, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple8[_, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple9[_, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple10[_, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple11[_, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gt(target: Iterable[_]) = op(oper, target.toList)
- def $gt[T: ValidDateOrNumericType](target: T) = op(oper, target)
+
+ def $gt[A : AsQueryParam](a: A) = op(oper, AsQueryParam[A].asQueryParam(a))
}
/**
@@ -321,34 +214,8 @@ trait GreaterThanOp extends QueryOperator {
*/
trait GreaterThanEqualOp extends QueryOperator {
private val oper = "$gte"
-
- def $gte(target: String) = op(oper, target)
- def $gte(target: DBObject) = op(oper, target)
- def $gte(target: Array[_]) = op(oper, target.toList)
- def $gte(target: Tuple1[_]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple2[_, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple3[_, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple4[_, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple5[_, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple6[_, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple7[_, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple8[_, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple9[_, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple10[_, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple11[_, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $gte(target: Iterable[_]) = op(oper, target.toList)
- def $gte[T: ValidDateOrNumericType](target: T) = op(oper, target)
+
+ def $gte[A : AsQueryParam](a: A) = op(oper, AsQueryParam[A].asQueryParam(a))
}
/**
@@ -369,30 +236,7 @@ trait GreaterThanEqualOp extends QueryOperator {
trait InOp extends QueryOperator {
private val oper = "$in"
- def $in(target: Array[_]) = op(oper, target.toList)
- def $in(target: Tuple1[_]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple2[_, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple3[_, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple4[_, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple5[_, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple6[_, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple7[_, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple8[_, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple9[_, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple10[_, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple11[_, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $in(target: Iterable[_]) = op(oper, target.toList)
+ def $in[A : AsQueryParam](a: A) = op(oper, AsQueryParam[A].asQueryParam(a))
}
/**
@@ -413,30 +257,7 @@ trait InOp extends QueryOperator {
trait NotInOp extends QueryOperator {
private val oper = "$nin"
- def $nin(target: Array[_]) = op(oper, target.toList)
- def $nin(target: Tuple1[_]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple2[_, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple3[_, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple4[_, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple5[_, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple6[_, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple7[_, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple8[_, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple9[_, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple10[_, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple11[_, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $nin(target: Iterable[_]) = op(oper, target.toList)
+ def $nin[A : AsQueryParam](a: A) = op(oper, AsQueryParam[A].asQueryParam(a))
}
/**
@@ -457,30 +278,7 @@ trait NotInOp extends QueryOperator {
trait AllOp extends QueryOperator {
private val oper = "$all"
- def $all(target: Array[_]) = op(oper, target.toList)
- def $all(target: Tuple1[_]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple2[_, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple3[_, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple4[_, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple5[_, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple6[_, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple7[_, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple8[_, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple9[_, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple10[_, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple11[_, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple12[_, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple13[_, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple14[_, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple15[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple16[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple17[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple18[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple19[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple20[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple21[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Tuple22[_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]) = op(oper, target.productIterator.toList)
- def $all(target: Iterable[_]) = op(oper, target.toList)
+ def $all[A : AsQueryParam](a: A) = op(oper, AsQueryParam[A].asQueryParam(a))
}
/**
View
60 casbah-query/src/main/scala/Implicits.scala
@@ -132,6 +132,66 @@ trait ValidBarewordExpressionArgTypeHolder {
implicit object CoreOperatorResultObjOk extends CoreOperatorResultObj
}
+trait AsIterable[A]{
+ def asIterable(a:A):Iterable[_]
+}
+
+object AsIterable {
+ def apply[A](implicit asIterable:AsIterable[A]) = asIterable
+
+ implicit def iterable[A <: Iterable[_]]:AsIterable[A] = new AsIterable[A]{
+ def asIterable(a: A) = a
+ }
+
+ implicit def product[A <: Product]:AsIterable[A] = new AsIterable[A]{
+ def asIterable(a: A) = a.productIterator.toIterable
+ }
+}
+
+@annotation.implicitNotFound("${A} is not a valid query parameter")
+trait AsQueryParam[A]{
+ def asQueryParam(a:A):Any
+}
+
+object AsQueryParam {
+ def apply[A](implicit a:AsQueryParam[A]) = a
+
+ private def as[A](f:A => Any):AsQueryParam[A] = new AsQueryParam[A]{
+ def asQueryParam(a: A) = f(a)
+ }
+
+ implicit val string = as[String](identity)
+ implicit def dbObject[A <: DBObject] = as[A](identity)
+ implicit val dbRef = as[DBRef](identity)
+ implicit val objectId = as[ObjectId](identity)
+ implicit val boolean = as[Boolean](identity)
+ implicit def array[A] = as[Array[A]](_.toList)
+ implicit def iterable[A <: Iterable[_]] = as[A](_.toList)
+ implicit def dateOrNumeric[A : ValidDateOrNumericType] = as[A](identity)
+ implicit def tuple1[A1] = as[Tuple1[A1]](_.productIterator.toList)
+ implicit def tuple2[A1,A2] = as[(A1,A2)](_.productIterator.toList)
+ implicit def tuple3[A1,A2,A3] = as[(A1,A2,A3)](_.productIterator.toList)
+ implicit def tuple4[A1,A2,A3,A4] = as[(A1,A2,A3,A4)](_.productIterator.toList)
+ implicit def tuple5[A1,A2,A3,A4,A5] = as[(A1,A2,A3,A4,A5)](_.productIterator.toList)
+ implicit def tuple6[A1,A2,A3,A4,A5,A6] = as[(A1,A2,A3,A4,A5,A6)](_.productIterator.toList)
+ implicit def tuple7[A1,A2,A3,A4,A5,A6,A7] = as[(A1,A2,A3,A4,A5,A6,A7)](_.productIterator.toList)
+ implicit def tuple8[A1,A2,A3,A4,A5,A6,A7,A8] = as[(A1,A2,A3,A4,A5,A6,A7,A8)](_.productIterator.toList)
+ implicit def tuple9[A1,A2,A3,A4,A5,A6,A7,A8,A9] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9)](_.productIterator.toList)
+ implicit def tuple10[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10)](_.productIterator.toList)
+ implicit def tuple11[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11)](_.productIterator.toList)
+ implicit def tuple12[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12)](_.productIterator.toList)
+ implicit def tuple13[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13)](_.productIterator.toList)
+ implicit def tuple14[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14)](_.productIterator.toList)
+ implicit def tuple15[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15)](_.productIterator.toList)
+ implicit def tuple16[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16)](_.productIterator.toList)
+ implicit def tuple17[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17)](_.productIterator.toList)
+ implicit def tuple18[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18)](_.productIterator.toList)
+ implicit def tuple19[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19)](_.productIterator.toList)
+ implicit def tuple20[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20)](_.productIterator.toList)
+ implicit def tuple21[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20,A21] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20,A21)](_.productIterator.toList)
+ implicit def tuple22[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20,A21,A22] = as[(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20,A21,A22)](_.productIterator.toList)
+}
+
trait ValidNumericType[T]
trait ValidDateType[T]
View
14 casbah-query/src/test/scala/BarewordOperatorsSpec.scala
@@ -151,9 +151,10 @@ class BarewordOperatorsSpec extends CasbahMutableSpecification {
val push = $pushAll("foo" -> ("bar", "baz", "x", "y"))
push must haveListEntry("$pushAll.foo", List("bar", "baz", "x", "y"))
}
- "Not allow a non-list value" in {
- ($pushAll("foo" -> "bar")) must throwA[IllegalArgumentException]
- }
+// IS NOW A COMPILE ERROR
+// "Not allow a non-list value" in {
+// ($pushAll("foo" -> "bar")) must throwA[IllegalArgumentException]
+// }
"Accept multiple value lists" in {
val push = $pushAll("foo" -> ("bar", "baz", "x", "y"), "n" -> (5, 10, 12, 238))
push must haveListEntry("$pushAll.foo", List("bar", "baz", "x", "y"))
@@ -227,9 +228,10 @@ class BarewordOperatorsSpec extends CasbahMutableSpecification {
val pull = $pullAll("foo" -> ("bar", "baz", "x", "y"))
pull must haveEntry("$pullAll.foo" -> Seq("bar", "baz", "x", "y"))
}
- "Not allow a non-list value" in {
- ($pullAll("foo" -> "bar")) must throwA[IllegalArgumentException]
- }
+// IS NOW COMPILE ERROR
+// "Not allow a non-list value" in {
+// ($pullAll("foo" -> "bar")) must throwA[IllegalArgumentException]
+// }
"Accept multiple value lists" in {
val pull = $pullAll("foo" -> ("bar", "baz", "x", "y"), "n" -> (5, 10, 12, 238))
pull must haveEntry("$pullAll.foo" -> Seq("bar", "baz", "x", "y"))
View
5 project/CasbahBuild.scala
@@ -34,14 +34,14 @@ object CasbahBuild extends Build {
)
lazy val defaultSettings = baseSettings ++ Seq(
- libraryDependencies ++= Seq(scalatest(scalaVersion), slf4j, slf4jJCL),
+ libraryDependencies ++= Seq(scalatest(scalaVersion), slf4j, slf4jJCL, junit),
libraryDependencies <<= (scalaVersion, libraryDependencies) { (sv, deps) =>
val versionMap = Map("2.8.0" -> ("specs2_2.8.0", "1.5"),
"2.8.1" -> ("specs2_2.8.1", "1.5"),
"2.9.0" -> ("specs2_2.9.0", "1.7.1"),
"2.9.0-1" -> ("specs2_2.9.0", "1.7.1"),
"2.9.1" -> ("specs2_2.9.1", "1.7.1"))
- val tuple = versionMap.getOrElse(sv, error("Unsupported Scala version for Specs2"))
+ val tuple = versionMap.getOrElse(sv, sys.error("Unsupported Scala version for Specs2"))
deps :+ ("org.specs2" % tuple._1 % tuple._2)
},
autoCompilerPlugins := true,
@@ -100,6 +100,7 @@ object Dependencies {
val specs2 = "org.specs2" %% "specs2" % "1.5.1" % "provided"
//val specs2 = specs2Compile % "test"
+ val junit = "junit" % "junit" % "4.10" % "test"
def specs2ScalazCore(scalaVer: sbt.SettingKey[String]) =
scalaVersionString(scalaVer) match {
View
2  project/build.properties
@@ -1 +1 @@
-sbt.version=0.11.1
+sbt.version=0.11.2
Please sign in to comment.
Something went wrong with that request. Please try again.