Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #411 from viktortnk/distinct-command
Implementation of 'Distinct' command
- Loading branch information
Showing
5 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package reactivemongo.api.commands.bson | ||
|
||
import reactivemongo.api.BSONSerializationPack | ||
import reactivemongo.api.commands._ | ||
import reactivemongo.bson._ | ||
|
||
object BSONDistinctCommand extends DistinctCommand[BSONSerializationPack.type] { | ||
val pack = BSONSerializationPack | ||
} | ||
|
||
object BSONDistinctCommandImplicits { | ||
import BSONDistinctCommand._ | ||
|
||
implicit object DistinctWriter extends BSONDocumentWriter[ResolvedCollectionCommand[Distinct]] { | ||
def write(distinct: ResolvedCollectionCommand[Distinct]): BSONDocument = | ||
BSONDocument( | ||
"distinct" -> distinct.collection, | ||
"key" -> distinct.command.keyString, | ||
"query" -> distinct.command.query) | ||
} | ||
|
||
implicit object DistinctResultReader extends DealingWithGenericCommandErrorsReader[DistinctResult] { | ||
def readResult(doc: BSONDocument): DistinctResult = | ||
DistinctResult(doc.getAs[BSONArray]("values").fold[List[BSONValue]](List())(_.values.toList)) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package reactivemongo.api.commands | ||
|
||
import reactivemongo.api.SerializationPack | ||
|
||
trait DistinctCommand[P <: SerializationPack] extends ImplicitCommandHelpers[P] { | ||
case class Distinct( | ||
//{ distinct: <collection>, key: <key>, query: <query> } | ||
keyString: String, | ||
query: Option[pack.Document]) extends CollectionCommand with CommandWithPack[pack.type] with CommandWithResult[DistinctResult] | ||
|
||
case class DistinctResult(values: List[pack.Value]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters