2016-04-01 05:41:57 -06:00
|
|
|
// Copyright (C) 2014 Fehmi Can Saglam (@fehmicans) and contributors.
|
|
|
|
// See the LICENCE.txt file distributed with this work for additional
|
|
|
|
// information regarding copyright ownership.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package lila.db
|
|
|
|
|
|
|
|
import ornicar.scalalib.Zero
|
|
|
|
import reactivemongo.api._
|
|
|
|
import reactivemongo.api.collections.GenericQueryBuilder
|
|
|
|
import reactivemongo.bson._
|
|
|
|
|
2016-10-29 02:57:55 -06:00
|
|
|
trait dsl extends LowPriorityDsl {
|
2016-04-01 05:41:57 -06:00
|
|
|
|
|
|
|
type Coll = reactivemongo.api.collections.bson.BSONCollection
|
2016-04-01 10:43:50 -06:00
|
|
|
type Bdoc = BSONDocument
|
2016-04-02 00:11:09 -06:00
|
|
|
type Barr = BSONArray
|
2016-04-01 05:41:57 -06:00
|
|
|
|
|
|
|
type QueryBuilder = GenericQueryBuilder[BSONSerializationPack.type]
|
|
|
|
|
|
|
|
type BSONValueReader[A] = BSONReader[_ <: BSONValue, A]
|
|
|
|
type BSONValueWriter[A] = BSONWriter[A, _ <: BSONValue]
|
|
|
|
type BSONValueHandler[A] = BSONHandler[_ <: BSONValue, A]
|
|
|
|
|
2016-07-02 13:34:09 -06:00
|
|
|
type BSONArrayReader[A] = BSONReader[BSONArray, A]
|
|
|
|
type BSONArrayWriter[A] = BSONWriter[A, BSONArray]
|
|
|
|
type BSONArrayHandler[A] = BSONHandler[BSONArray, A]
|
|
|
|
|
2016-04-01 05:41:57 -06:00
|
|
|
implicit val LilaBSONDocumentZero: Zero[BSONDocument] =
|
2016-04-01 10:43:50 -06:00
|
|
|
Zero.instance($doc())
|
2016-04-01 05:41:57 -06:00
|
|
|
|
|
|
|
implicit def bsonDocumentToPretty(document: BSONDocument): String = {
|
|
|
|
BSONDocument.pretty(document)
|
|
|
|
}
|
|
|
|
|
|
|
|
//**********************************************************************************************//
|
|
|
|
// Helpers
|
|
|
|
def $empty: BSONDocument = BSONDocument.empty
|
|
|
|
|
2016-04-02 02:45:54 -06:00
|
|
|
def $doc(elements: Producer[BSONElement]*): BSONDocument = BSONDocument(elements: _*)
|
2016-04-01 05:41:57 -06:00
|
|
|
|
|
|
|
def $doc(elements: Traversable[BSONElement]): BSONDocument = BSONDocument(elements)
|
|
|
|
|
|
|
|
def $arr(elements: Producer[BSONValue]*): BSONArray = {
|
|
|
|
BSONArray(elements: _*)
|
|
|
|
}
|
|
|
|
|
2016-04-01 10:43:50 -06:00
|
|
|
def $id[T](id: T)(implicit writer: BSONWriter[T, _ <: BSONValue]): BSONDocument = $doc("_id" -> id)
|
2016-04-01 05:41:57 -06:00
|
|
|
|
|
|
|
def $inIds[T](ids: Iterable[T])(implicit writer: BSONWriter[T, _ <: BSONValue]): BSONDocument =
|
2016-04-02 05:35:06 -06:00
|
|
|
$id($doc("$in" -> ids))
|
2016-04-01 05:41:57 -06:00
|
|
|
|
|
|
|
def $boolean(b: Boolean) = BSONBoolean(b)
|
|
|
|
def $string(s: String) = BSONString(s)
|
2016-04-01 10:43:50 -06:00
|
|
|
def $int(i: Int) = BSONInteger(i)
|
2016-04-01 05:41:57 -06:00
|
|
|
|
|
|
|
// End of Helpers
|
|
|
|
//**********************************************************************************************//
|
|
|
|
|
|
|
|
//**********************************************************************************************//
|
|
|
|
// Top Level Logical Operators
|
|
|
|
def $or(expressions: BSONDocument*): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$or" -> expressions)
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def $and(expressions: BSONDocument*): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$and" -> expressions)
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def $nor(expressions: BSONDocument*): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$nor" -> expressions)
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
// End of Top Level Logical Operators
|
|
|
|
//**********************************************************************************************//
|
|
|
|
|
|
|
|
//**********************************************************************************************//
|
|
|
|
// Top Level Evaluation Operators
|
|
|
|
def $text(search: String): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$text" -> $doc("$search" -> search))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def $text(search: String, language: String): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$text" -> $doc("$search" -> search, "$language" -> language))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def $where(expression: String): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$where" -> expression)
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
// End of Top Level Evaluation Operators
|
|
|
|
//**********************************************************************************************//
|
|
|
|
|
|
|
|
//**********************************************************************************************//
|
|
|
|
// Top Level Field Update Operators
|
|
|
|
def $inc(item: Producer[BSONElement], items: Producer[BSONElement]*): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$inc" -> $doc((Seq(item) ++ items): _*))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
def $inc(items: Iterable[BSONElement]): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$inc" -> $doc(items))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def $mul(item: Producer[BSONElement]): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$mul" -> $doc(item))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def $rename(item: (String, String), items: (String, String)*)(implicit writer: BSONWriter[String, _ <: BSONValue]): BSONDocument = {
|
2016-10-29 02:57:55 -06:00
|
|
|
$doc("$rename" -> $doc((item +: items).
|
|
|
|
map { case (k, v) => BSONElement(k, BSONString(v)) }))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def $setOnInsert(item: Producer[BSONElement], items: Producer[BSONElement]*): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$setOnInsert" -> $doc((Seq(item) ++ items): _*))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def $set(item: Producer[BSONElement], items: Producer[BSONElement]*): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$set" -> $doc((Seq(item) ++ items): _*))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def $unset(field: String, fields: String*): BSONDocument = {
|
2016-10-29 02:57:55 -06:00
|
|
|
$doc("$unset" -> $doc((Seq(field) ++ fields).map(k => BSONElement(k, BSONString("")))))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
2019-03-20 20:32:20 -06:00
|
|
|
def $setBoolOrUnset(field: String, value: Boolean): BSONDocument = {
|
|
|
|
if (value) $set(field -> true) else $unset(field)
|
|
|
|
}
|
|
|
|
|
2016-04-01 05:41:57 -06:00
|
|
|
def $min(item: Producer[BSONElement]): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$min" -> $doc(item))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def $max(item: Producer[BSONElement]): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$max" -> $doc(item))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Helpers
|
|
|
|
def $eq[T](value: T)(implicit writer: BSONWriter[T, _ <: BSONValue]) = $doc("$eq" -> value)
|
|
|
|
|
|
|
|
def $gt[T](value: T)(implicit writer: BSONWriter[T, _ <: BSONValue]) = $doc("$gt" -> value)
|
|
|
|
|
|
|
|
/** Matches values that are greater than or equal to the value specified in the query. */
|
|
|
|
def $gte[T](value: T)(implicit writer: BSONWriter[T, _ <: BSONValue]) = $doc("$gte" -> value)
|
|
|
|
|
|
|
|
/** Matches any of the values that exist in an array specified in the query.*/
|
|
|
|
def $in[T](values: T*)(implicit writer: BSONWriter[T, _ <: BSONValue]) = $doc("$in" -> values)
|
|
|
|
|
|
|
|
/** Matches values that are less than the value specified in the query. */
|
|
|
|
def $lt[T](value: T)(implicit writer: BSONWriter[T, _ <: BSONValue]) = $doc("$lt" -> value)
|
|
|
|
|
|
|
|
/** Matches values that are less than or equal to the value specified in the query. */
|
|
|
|
def $lte[T](value: T)(implicit writer: BSONWriter[T, _ <: BSONValue]) = $doc("$lte" -> value)
|
|
|
|
|
|
|
|
/** Matches all values that are not equal to the value specified in the query. */
|
2016-04-01 10:43:50 -06:00
|
|
|
def $ne[T](value: T)(implicit writer: BSONWriter[T, _ <: BSONValue]) = $doc("$ne" -> value)
|
2016-04-01 05:41:57 -06:00
|
|
|
|
|
|
|
/** Matches values that do not exist in an array specified to the query. */
|
|
|
|
def $nin[T](values: T*)(implicit writer: BSONWriter[T, _ <: BSONValue]) = $doc("$nin" -> values)
|
|
|
|
|
2016-04-01 10:43:50 -06:00
|
|
|
def $exists(value: Boolean) = $doc("$exists" -> value)
|
|
|
|
|
2016-04-01 05:41:57 -06:00
|
|
|
trait CurrentDateValueProducer[T] {
|
|
|
|
def produce: BSONValue
|
|
|
|
}
|
|
|
|
|
|
|
|
implicit class BooleanCurrentDateValueProducer(value: Boolean) extends CurrentDateValueProducer[Boolean] {
|
|
|
|
def produce: BSONValue = BSONBoolean(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
implicit class StringCurrentDateValueProducer(value: String) extends CurrentDateValueProducer[String] {
|
|
|
|
def isValid: Boolean = Seq("date", "timestamp") contains value
|
|
|
|
|
|
|
|
def produce: BSONValue = {
|
|
|
|
if (!isValid)
|
|
|
|
throw new IllegalArgumentException(value)
|
|
|
|
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$type" -> value)
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def $currentDate(items: (String, CurrentDateValueProducer[_])*): BSONDocument = {
|
2016-10-29 02:57:55 -06:00
|
|
|
$doc("$currentDate" -> $doc(items.map(item => BSONElement(item._1, item._2.produce))))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
// End of Top Level Field Update Operators
|
|
|
|
//**********************************************************************************************//
|
|
|
|
|
|
|
|
//**********************************************************************************************//
|
|
|
|
// Top Level Array Update Operators
|
|
|
|
def $addToSet(item: Producer[BSONElement], items: Producer[BSONElement]*): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$addToSet" -> $doc((Seq(item) ++ items): _*))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def $pop(item: (String, Int)): BSONDocument = {
|
|
|
|
if (item._2 != -1 && item._2 != 1)
|
|
|
|
throw new IllegalArgumentException(s"${item._2} is not equal to: -1 | 1")
|
|
|
|
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$pop" -> $doc(item))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def $push(item: Producer[BSONElement]): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$push" -> $doc(item))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def $pushEach[T](field: String, values: T*)(implicit writer: BSONWriter[T, _ <: BSONValue]): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc(
|
|
|
|
"$push" -> $doc(
|
|
|
|
field -> $doc(
|
2016-04-01 05:41:57 -06:00
|
|
|
"$each" -> values
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
def $pull(item: Producer[BSONElement]): BSONDocument = {
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc("$pull" -> $doc(item))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
// End ofTop Level Array Update Operators
|
|
|
|
//**********************************************************************************************//
|
|
|
|
|
2019-08-22 12:19:21 -06:00
|
|
|
def Facet(doc: Bdoc) = reactivemongo.api.collections.bson.BSONBatchCommands.AggregationFramework.PipelineOperator($doc("$facet" -> doc))
|
|
|
|
|
2016-04-01 05:41:57 -06:00
|
|
|
/**
|
2017-10-16 11:09:30 -06:00
|
|
|
* Represents the initial state of the expression which has only the name of the field.
|
2016-04-01 05:41:57 -06:00
|
|
|
* It does not know the value of the expression.
|
|
|
|
*/
|
|
|
|
trait ElementBuilder {
|
|
|
|
def field: String
|
|
|
|
def append(value: BSONDocument): BSONDocument = value
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Represents the state of an expression which has a field and a value */
|
|
|
|
trait Expression[V <: BSONValue] extends ElementBuilder {
|
|
|
|
def value: V
|
2016-04-01 10:43:50 -06:00
|
|
|
def toBdoc(implicit writer: BSONWriter[V, _ <: BSONValue]) = toBSONDocument(this)
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This type of expressions cannot be cascaded. Examples:
|
|
|
|
*
|
|
|
|
* {{{
|
|
|
|
* "price" $eq 10
|
|
|
|
* "price" $ne 1000
|
|
|
|
* "size" $in ("S", "M", "L")
|
|
|
|
* "size" $nin ("S", "XXL")
|
|
|
|
* }}}
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
case class SimpleExpression[V <: BSONValue](field: String, value: V)
|
|
|
|
extends Expression[V]
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expressions of this type can be cascaded. Examples:
|
|
|
|
*
|
|
|
|
* {{{
|
|
|
|
* "age" $gt 50 $lt 60
|
|
|
|
* "age" $gte 50 $lte 60
|
|
|
|
* }}}
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
case class CompositeExpression(field: String, value: BSONDocument)
|
2017-08-23 17:56:39 -06:00
|
|
|
extends Expression[BSONDocument]
|
|
|
|
with ComparisonOperators {
|
2016-04-01 05:41:57 -06:00
|
|
|
override def append(value: BSONDocument): BSONDocument = {
|
|
|
|
this.value ++ value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** MongoDB comparison operators. */
|
|
|
|
trait ComparisonOperators { self: ElementBuilder =>
|
|
|
|
|
|
|
|
def $eq[T](value: T)(implicit writer: BSONWriter[T, _ <: BSONValue]): SimpleExpression[BSONValue] = {
|
|
|
|
SimpleExpression(field, writer.write(value))
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Matches values that are greater than the value specified in the query. */
|
|
|
|
def $gt[T](value: T)(implicit writer: BSONWriter[T, _ <: BSONValue]): CompositeExpression = {
|
2016-04-01 10:43:50 -06:00
|
|
|
CompositeExpression(field, append($doc("$gt" -> value)))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Matches values that are greater than or equal to the value specified in the query. */
|
|
|
|
def $gte[T](value: T)(implicit writer: BSONWriter[T, _ <: BSONValue]): CompositeExpression = {
|
2016-04-01 10:43:50 -06:00
|
|
|
CompositeExpression(field, append($doc("$gte" -> value)))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Matches any of the values that exist in an array specified in the query.*/
|
2016-07-18 04:10:45 -06:00
|
|
|
def $in[T](values: Iterable[T])(implicit writer: BSONWriter[T, _ <: BSONValue]): SimpleExpression[BSONDocument] = {
|
2016-04-01 10:43:50 -06:00
|
|
|
SimpleExpression(field, $doc("$in" -> values))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Matches values that are less than the value specified in the query. */
|
|
|
|
def $lt[T](value: T)(implicit writer: BSONWriter[T, _ <: BSONValue]): CompositeExpression = {
|
2016-04-01 10:43:50 -06:00
|
|
|
CompositeExpression(field, append($doc("$lt" -> value)))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Matches values that are less than or equal to the value specified in the query. */
|
|
|
|
def $lte[T](value: T)(implicit writer: BSONWriter[T, _ <: BSONValue]): CompositeExpression = {
|
2016-04-01 10:43:50 -06:00
|
|
|
CompositeExpression(field, append($doc("$lte" -> value)))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Matches all values that are not equal to the value specified in the query. */
|
|
|
|
def $ne[T](value: T)(implicit writer: BSONWriter[T, _ <: BSONValue]): SimpleExpression[BSONDocument] = {
|
2016-04-01 10:43:50 -06:00
|
|
|
SimpleExpression(field, $doc("$ne" -> value))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Matches values that do not exist in an array specified to the query. */
|
2016-07-18 04:10:45 -06:00
|
|
|
def $nin[T](values: Iterable[T])(implicit writer: BSONWriter[T, _ <: BSONValue]): SimpleExpression[BSONDocument] = {
|
2016-04-01 10:43:50 -06:00
|
|
|
SimpleExpression(field, $doc("$nin" -> values))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
trait LogicalOperators { self: ElementBuilder =>
|
|
|
|
def $not(f: (String => Expression[BSONDocument])): SimpleExpression[BSONDocument] = {
|
|
|
|
val expression = f(field)
|
2016-04-01 10:43:50 -06:00
|
|
|
SimpleExpression(field, $doc("$not" -> expression.value))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait ElementOperators { self: ElementBuilder =>
|
|
|
|
def $exists(exists: Boolean): SimpleExpression[BSONDocument] = {
|
2016-04-01 10:43:50 -06:00
|
|
|
SimpleExpression(field, $doc("$exists" -> exists))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait EvaluationOperators { self: ElementBuilder =>
|
2018-04-05 14:21:47 -06:00
|
|
|
def $mod(divisor: Int, remainder: Int): SimpleExpression[BSONDocument] =
|
2016-04-01 10:43:50 -06:00
|
|
|
SimpleExpression(field, $doc("$mod" -> BSONArray(divisor, remainder)))
|
2016-04-01 05:41:57 -06:00
|
|
|
|
2018-04-05 14:21:47 -06:00
|
|
|
def $regex(value: String, options: String = ""): SimpleExpression[BSONRegex] =
|
2016-04-01 05:41:57 -06:00
|
|
|
SimpleExpression(field, BSONRegex(value, options))
|
2018-04-05 14:21:47 -06:00
|
|
|
|
|
|
|
def $startsWith(value: String): SimpleExpression[BSONRegex] =
|
|
|
|
$regex(s"^$value", "")
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
trait ArrayOperators { self: ElementBuilder =>
|
2016-07-12 17:31:26 -06:00
|
|
|
def $all[T](values: Seq[T])(implicit writer: BSONWriter[T, _ <: BSONValue]): SimpleExpression[BSONDocument] = {
|
2016-04-01 10:43:50 -06:00
|
|
|
SimpleExpression(field, $doc("$all" -> values))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def $elemMatch(query: Producer[BSONElement]*): SimpleExpression[BSONDocument] = {
|
2016-04-01 10:43:50 -06:00
|
|
|
SimpleExpression(field, $doc("$elemMatch" -> $doc(query: _*)))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
def $size(size: Int): SimpleExpression[BSONDocument] = {
|
2016-04-01 10:43:50 -06:00
|
|
|
SimpleExpression(field, $doc("$size" -> size))
|
2016-04-01 05:41:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object $sort {
|
|
|
|
|
|
|
|
def asc(field: String) = $doc(field -> 1)
|
|
|
|
def desc(field: String) = $doc(field -> -1)
|
|
|
|
|
|
|
|
val naturalAsc = asc("$natural")
|
|
|
|
val naturalDesc = desc("$natural")
|
|
|
|
val naturalOrder = naturalDesc
|
|
|
|
|
|
|
|
val createdAsc = asc("createdAt")
|
|
|
|
val createdDesc = desc("createdAt")
|
|
|
|
val updatedDesc = desc("updatedAt")
|
|
|
|
}
|
|
|
|
|
|
|
|
implicit class ElementBuilderLike(val field: String)
|
|
|
|
extends ElementBuilder
|
|
|
|
with ComparisonOperators
|
|
|
|
with ElementOperators
|
|
|
|
with EvaluationOperators
|
|
|
|
with LogicalOperators
|
|
|
|
with ArrayOperators
|
|
|
|
|
|
|
|
implicit def toBSONDocument[V <: BSONValue](expression: Expression[V])(implicit writer: BSONWriter[V, _ <: BSONValue]): BSONDocument =
|
2016-04-01 10:43:50 -06:00
|
|
|
$doc(expression.field -> expression.value)
|
2016-04-01 05:41:57 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-10-29 02:57:55 -06:00
|
|
|
sealed trait LowPriorityDsl { self: dsl =>
|
|
|
|
// Priority lower than toBSONDocument
|
|
|
|
implicit def toBSONElement[V <: BSONValue](expression: Expression[V])(implicit writer: BSONWriter[V, _ <: BSONValue]): Producer[BSONElement] = {
|
|
|
|
BSONElement(expression.field, expression.value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-02 04:13:25 -06:00
|
|
|
object dsl extends dsl with CollExt with QueryBuilderExt with CursorExt with Handlers
|