Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract mongo-derivation #189

Merged
merged 1 commit into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)}

}