I am looking to implement my DAO access layer using Scala 2.9.x and Casbah. Given my entity is a case class with parameters:
case class Price (Id: Option[String], Price: Double, ItemName: String)
and my BSON document looks like:
{
"_id" : ObjectId("55dd1874b46f7178c8ddb737"),
"ItemName" : "Beet",
"Price" : "6"
}
I try to create a property
override var prices: List[Price] =
db("prices").find.toList.map(
o => Price(Some(o("_id").toString),
o("Price").toString.toDouble,
o.getAs[String]("ItemName").get ))
Here are my main concerns: 1. Mapping fields looks a little cumbersome, there should be some automation for that. I know I can use parser from import net.liftweb.json.{DefaultFormats, Serialization} or any other but I am pretty sure there should be something closer related to Casbah. May be it can be some other MongoDB Scala ORM. 2. I do not like the idea of putting that to var. What is the better way of exposing data? Should I use property? 3. What is the best practice for entites (as you can see I use case class with parameters without any body)