-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
883 additions
and
221 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
rule = ReactiveMongoUpgrade | ||
*/ | ||
package fix | ||
|
||
import scala.concurrent.{ ExecutionContext, Future } | ||
|
||
import reactivemongo.api.{ MongoDriver, MongoConnection } | ||
import reactivemongo.api.commands.{ CollStatsResult, WriteConcern } | ||
|
||
import reactivemongo.api.commands.MultiBulkWriteResult | ||
|
||
import reactivemongo.api.collections.GenericCollection | ||
import reactivemongo.api.collections.bson.BSONCollection | ||
|
||
import com.github.ghik.silencer.silent | ||
|
||
object Commands { | ||
def collStats(drv: MongoDriver, wc: WriteConcern): Future[CollStatsResult] = ??? | ||
|
||
def bulk: Future[MultiBulkWriteResult] = ??? | ||
} | ||
|
||
object Drv { | ||
def connect(d: MongoDriver) = d.connection("mongodb://...") | ||
|
||
def closeCon(con: MongoConnection) = con.askClose()(null) | ||
|
||
@silent | ||
def conFromStr(uri: String)(implicit ec: ExecutionContext) = | ||
MongoConnection.parseURI(uri) | ||
} | ||
|
||
object Coll { | ||
import reactivemongo.bson.BSONDocument | ||
|
||
@silent def rename1(coll: GenericCollection[_])( | ||
implicit | ||
ec: ExecutionContext) = coll.rename("foo") | ||
|
||
@silent def rename2(coll: BSONCollection)( | ||
implicit | ||
ec: ExecutionContext) = coll.rename("foo", false) | ||
|
||
def query1(coll: BSONCollection) = { | ||
val qry = coll.find(BSONDocument.empty, BSONDocument("bar" -> 1)). | ||
partial | ||
|
||
val b = qry.sortOption | ||
val c = qry.projectionOption | ||
val d = qry.hintOption | ||
val e = qry.explainFlag | ||
val f = qry.snapshotFlag | ||
val g = qry.commentString | ||
val h = qry.maxTimeMsOption | ||
|
||
if (System.currentTimeMillis() == -1) { | ||
println(s"b=$b,c=$c,d=$d,e=$e,f=$f,g=$g,h=$h") | ||
} | ||
} | ||
|
||
def query2(coll: BSONCollection) = coll.find( | ||
projection = BSONDocument("lorem" -> 1), | ||
selector = BSONDocument.empty) | ||
|
||
@silent | ||
def agg1(coll: BSONCollection)(implicit ec: ExecutionContext) = | ||
coll.aggregateWith1[BSONDocument](explain = true, true) { f => | ||
import f._ | ||
|
||
val m = Match(BSONDocument("foo" -> 1)) | ||
val _ = m.makePipe | ||
|
||
m -> List(Out("bar")) | ||
} | ||
|
||
def agg2(coll: BSONCollection) = coll.BatchCommands.AggregationFramework | ||
|
||
def remove1(coll: BSONCollection)(implicit ec: ExecutionContext) = | ||
coll.remove(BSONDocument("foo" -> 1)) | ||
|
||
def remove2( | ||
coll: BSONCollection, | ||
wc: WriteConcern)(implicit ec: ExecutionContext) = coll.remove( | ||
firstMatchOnly = true, | ||
selector = BSONDocument("foo" -> 1), | ||
writeConcern = wc) | ||
|
||
def insert1(coll: BSONCollection)(implicit ec: ExecutionContext) = | ||
coll.insert(BSONDocument("bar" -> 1)) | ||
|
||
def insert2( | ||
coll: BSONCollection, | ||
wc: WriteConcern)(implicit ec: ExecutionContext) = | ||
coll.insert[BSONDocument]( | ||
writeConcern = wc, | ||
document = BSONDocument("bar" -> 1)) | ||
|
||
def update1(coll: BSONCollection)(implicit ec: ExecutionContext) = | ||
coll.update[BSONDocument, BSONDocument]( | ||
BSONDocument("foo" -> 1), BSONDocument("bar" -> "lorem")) | ||
|
||
def update2(coll: BSONCollection, wc: WriteConcern)( | ||
implicit | ||
ec: ExecutionContext) = coll.update( | ||
writeConcern = wc, | ||
update = BSONDocument("bar" -> "lorem"), | ||
selector = BSONDocument("foo" -> 1), | ||
multi = false, | ||
upsert = true) | ||
|
||
} |
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,97 @@ | ||
package fix | ||
|
||
import scala.concurrent.{ ExecutionContext, Future } | ||
|
||
import reactivemongo.api.MongoConnection | ||
|
||
|
||
import reactivemongo.api.collections.GenericCollection | ||
import reactivemongo.api.bson.collection.BSONCollection | ||
|
||
import com.github.ghik.silencer.silent | ||
import reactivemongo.api.{ AsyncDriver, CollectionStats, WriteConcern } | ||
import reactivemongo.api.bson.BSONDocument | ||
|
||
object Commands { | ||
def collStats(drv: AsyncDriver, wc: WriteConcern): Future[CollectionStats] = ??? | ||
|
||
def bulk: Future[Any /* MultiBulkWriteResult ~> anyCollection.MultiBulkWriteResult */] = ??? | ||
} | ||
|
||
object Drv { | ||
def connect(d: AsyncDriver) = d.connect("mongodb://...") | ||
|
||
def closeCon(con: MongoConnection) = con.close()(null) | ||
|
||
@silent | ||
def conFromStr(uri: String)(implicit ec: ExecutionContext) = | ||
MongoConnection.fromString(uri) | ||
} | ||
|
||
object Coll { | ||
|
||
@silent def rename1(coll: GenericCollection[_])( | ||
implicit | ||
ec: ExecutionContext) = coll.db.connection.database("admin").flatMap(_.renameCollection(coll.db.name, coll.name, "foo")) | ||
|
||
@silent def rename2(coll: BSONCollection)( | ||
implicit | ||
ec: ExecutionContext) = coll.db.connection.database("admin").flatMap(_.renameCollection(coll.db.name, coll.name, "foo", false)) | ||
|
||
def query1(coll: BSONCollection) = { | ||
val qry = coll.find(BSONDocument.empty, Some(BSONDocument("bar" -> 1))). | ||
allowPartialResults | ||
|
||
val b = qry.sort | ||
val c = qry.projection | ||
val d = qry.hint | ||
val e = qry.explain | ||
val f = qry.snapshot | ||
val g = qry.comment | ||
val h = qry.maxTimeMs | ||
|
||
if (System.currentTimeMillis() == -1) { | ||
println(s"b=$b,c=$c,d=$d,e=$e,f=$f,g=$g,h=$h") | ||
} | ||
} | ||
|
||
def query2(coll: BSONCollection) = coll.find(selector = BSONDocument.empty, projection = Some(BSONDocument("lorem" -> 1))) | ||
|
||
@silent | ||
def agg1(coll: BSONCollection)(implicit ec: ExecutionContext) = | ||
coll.aggregateWith[BSONDocument](explain = true, true) { f => | ||
import f._ | ||
|
||
val m = Match(BSONDocument("foo" -> 1)) | ||
val _ = m | ||
|
||
m -> List(Out("bar")) | ||
} | ||
|
||
def agg2(coll: BSONCollection) = coll.AggregationFramework | ||
|
||
def remove1(coll: BSONCollection)(implicit ec: ExecutionContext) = | ||
coll.delete.one(q = BSONDocument("foo" -> 1)) | ||
|
||
def remove2( | ||
coll: BSONCollection, | ||
wc: WriteConcern)(implicit ec: ExecutionContext) = coll.delete(writeConcern = wc).one(q = BSONDocument("foo" -> 1), limit = { | ||
if (true) Some(1) else None | ||
}) | ||
|
||
def insert1(coll: BSONCollection)(implicit ec: ExecutionContext) = | ||
coll.insert.one(BSONDocument("bar" -> 1)) | ||
|
||
def insert2( | ||
coll: BSONCollection, | ||
wc: WriteConcern)(implicit ec: ExecutionContext) = | ||
coll.insert(writeConcern = wc).one[BSONDocument](BSONDocument("bar" -> 1)) | ||
|
||
def update1(coll: BSONCollection)(implicit ec: ExecutionContext) = | ||
coll.update.one[BSONDocument, BSONDocument](q = BSONDocument("foo" -> 1), u = BSONDocument("bar" -> "lorem")) | ||
|
||
def update2(coll: BSONCollection, wc: WriteConcern)( | ||
implicit | ||
ec: ExecutionContext) = coll.update(writeConcern = wc).one(q = BSONDocument("foo" -> 1), u = BSONDocument("bar" -> "lorem"), upsert = true, multi = false) | ||
|
||
} |
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
Oops, something went wrong.