2016-04-01 10:43:50 -06:00
|
|
|
package lila.db
|
|
|
|
|
2019-12-08 01:02:12 -07:00
|
|
|
import scala.collection.Factory
|
2016-04-01 10:43:50 -06:00
|
|
|
|
2020-07-19 07:11:06 -06:00
|
|
|
import scala.concurrent.ExecutionContext
|
|
|
|
|
2020-07-30 03:37:46 -06:00
|
|
|
import reactivemongo.api._
|
2020-07-19 07:11:06 -06:00
|
|
|
|
2016-04-02 02:45:54 -06:00
|
|
|
trait QueryBuilderExt { self: dsl =>
|
2020-07-19 07:11:06 -06:00
|
|
|
implicit final class ExtendCursor[A](cursor: Cursor.WithOps[A])(implicit ec: ExecutionContext) { // CursorProducer?
|
|
|
|
|
|
|
|
def gather[M[_]](upTo: Int)(implicit factory: Factory[A, M[A]]): Fu[M[A]] =
|
|
|
|
cursor.collect[M](upTo, Cursor.ContOnError[M[A]]())
|
|
|
|
|
|
|
|
def list(): Fu[List[A]] =
|
|
|
|
gather[List](Int.MaxValue)
|
2016-04-01 10:43:50 -06:00
|
|
|
|
2020-07-19 07:11:06 -06:00
|
|
|
def list(limit: Int): Fu[List[A]] =
|
|
|
|
gather[List](limit)
|
|
|
|
|
|
|
|
def list(limit: Option[Int]): Fu[List[A]] =
|
|
|
|
gather[List](limit | Int.MaxValue)
|
|
|
|
|
|
|
|
def vector(limit: Int): Fu[Vector[A]] =
|
|
|
|
gather[Vector](limit)
|
|
|
|
|
|
|
|
}
|
2016-04-01 10:43:50 -06:00
|
|
|
}
|