Skip to content

Commit

Permalink
Merge pull request #189 from sphereio/extract_mongo_derivation
Browse files Browse the repository at this point in the history
extract mongo-derivation
  • Loading branch information
yanns authored Apr 29, 2020
2 parents 6b1d12b + a83a731 commit 434c48e
Show file tree
Hide file tree
Showing 25 changed files with 31 additions and 4 deletions.
13 changes: 11 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,20 @@ lazy val `sphere-json` = project.in(file("./json"))
.settings(homepage := Some(url("https://github.com/sphereio/sphere-scala-libs/blob/master/json/README.md")))
.dependsOn(`sphere-util`)

lazy val `sphere-mongo` = project.in(file("./mongo"))
lazy val `sphere-mongo-core` = project.in(file("./mongo/mongo-core"))
.settings(standardSettings: _*)
.settings(Fmpp.settings: _*)
.dependsOn(`sphere-util`)

lazy val `sphere-mongo-derivation` = project.in(file("./mongo/mongo-derivation"))
.settings(standardSettings: _*)
.settings(Fmpp.settings: _*)
.dependsOn(`sphere-mongo-core`)

lazy val `sphere-mongo` = project.in(file("./mongo"))
.settings(standardSettings: _*)
.settings(homepage := Some(url("https://github.com/sphereio/sphere-scala-libs/blob/master/mongo/README.md")))
.aggregate(`sphere-mongo-core`, `sphere-mongo-derivation`)

// benchmarks

lazy val benchmarks = project
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.sphere.mongo.format

import java.util.Locale

import com.mongodb.DBObject
import io.sphere.mongo.MongoUtils
import io.sphere.mongo.format.DefaultMongoFormats._
import io.sphere.mongo.generic._
import io.sphere.util.LangTag
import org.bson.BasicBSONObject
import org.bson.types.BasicBSONList
Expand All @@ -16,7 +18,14 @@ import scala.collection.JavaConverters._
object DefaultMongoFormatsTest {
case class User(name: String)
object User {
implicit val mongo: MongoFormat[User] = mongoProduct(apply _)
implicit val mongo: MongoFormat[User] = new MongoFormat[User] {
override def toMongoValue(a: User): Any = MongoUtils.dbObj("name" -> a.name)
override def fromMongoValue(any: Any): User = any match {
case dbo: DBObject =>
User(dbo.get("name").asInstanceOf[String])
case _ => throw new Exception("expected DBObject")
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.sphere.mongo
import com.mongodb.BasicDBObject

object MongoUtils {

def dbObj(pairs: (String, Any)*) =
pairs.foldLeft(new BasicDBObject){case (obj, (key, value)) => obj.append(key, value)}

}

0 comments on commit 434c48e

Please sign in to comment.