more db rewrite
parent
0aa524a4b9
commit
1eedc9082b
|
@ -2,13 +2,9 @@ package lila.db
|
|||
|
||||
import scala.util.{ Try, Success, Failure }
|
||||
|
||||
import play.api.data.validation.ValidationError
|
||||
import play.api.libs.json._
|
||||
import reactivemongo.bson._
|
||||
import reactivemongo.bson.utils.Converters
|
||||
|
||||
import lila.common.PimpedJson._
|
||||
|
||||
case class ByteArray(value: Array[Byte]) {
|
||||
|
||||
def isEmpty = value.isEmpty
|
||||
|
@ -36,21 +32,6 @@ object ByteArray {
|
|||
def write(ba: ByteArray) = BSONBinary(ba.value, subtype)
|
||||
}
|
||||
|
||||
implicit object JsByteArrayFormat extends OFormat[ByteArray] {
|
||||
|
||||
def reads(json: JsValue) = (for {
|
||||
hexStr ← json str "$binary"
|
||||
bytes ← fromHexStr(hexStr).toOption
|
||||
} yield bytes) match {
|
||||
case None => JsError(s"error reading ByteArray from $json")
|
||||
case Some(ba) => JsSuccess(ba)
|
||||
}
|
||||
|
||||
def writes(byteArray: ByteArray) = Json.obj(
|
||||
"$binary" -> byteArray.toHexStr,
|
||||
"$type" -> binarySubType)
|
||||
}
|
||||
|
||||
def parseByte(s: String): Byte = {
|
||||
var i = s.length - 1
|
||||
var sum = 0
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package lila.db
|
||||
|
||||
import dsl._
|
||||
|
||||
import reactivemongo.api._
|
||||
import reactivemongo.bson._
|
||||
|
||||
trait CollExt {
|
||||
trait CollExt { self: dsl =>
|
||||
|
||||
final implicit class ExtendColl(coll: Coll) {
|
||||
|
||||
|
@ -72,10 +70,10 @@ trait CollExt {
|
|||
}
|
||||
|
||||
def updateField[V: BSONValueWriter](selector: BSONDocument, field: String, value: V) =
|
||||
coll.update(selector, $doc(field -> value))
|
||||
coll.update(selector, $set(field -> value))
|
||||
|
||||
def updateFieldUnchecked[V: BSONValueWriter](selector: BSONDocument, field: String, value: V) =
|
||||
coll.uncheckedUpdate(selector, $doc(field -> value))
|
||||
coll.uncheckedUpdate(selector, $set(field -> value))
|
||||
|
||||
def fetchUpdate[D: BSONDocumentHandler](selector: BSONDocument)(update: D => BSONDocument): Funit =
|
||||
one[D](selector) flatMap {
|
||||
|
@ -85,5 +83,3 @@ trait CollExt {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
object CollExt extends CollExt
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package lila.db
|
||||
|
||||
import dsl._
|
||||
|
||||
import org.joda.time.DateTime
|
||||
import reactivemongo.bson._
|
||||
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package lila.db
|
||||
|
||||
import dsl._
|
||||
|
||||
import reactivemongo.api._
|
||||
import reactivemongo.api.collections.GenericQueryBuilder
|
||||
import reactivemongo.bson._
|
||||
|
||||
trait QueryBuilderExt {
|
||||
trait QueryBuilderExt { self: dsl =>
|
||||
|
||||
final implicit class ExtendQueryBuilder[A](val b: dsl.QueryBuilder) {
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ trait dsl {
|
|||
// Helpers
|
||||
def $empty: BSONDocument = BSONDocument.empty
|
||||
|
||||
def $doc(elements: Producer[BSONElement]*): BSONDocument = $doc(elements: _*)
|
||||
def $doc(elements: Producer[BSONElement]*): BSONDocument = BSONDocument(elements: _*)
|
||||
|
||||
def $doc(elements: Traversable[BSONElement]): BSONDocument = BSONDocument(elements)
|
||||
|
||||
|
|
Loading…
Reference in New Issue