eigengo / scalad

Scala Data access for NoSQL databases
47 stars 15 forks source link

Implement convenient DSL for DBObject #51

Open janm399 opened 11 years ago

janm399 commented 11 years ago

Implement implicit conversions to DBObject using some convenient DSL so that you can use it nicely in the MongoSearch.searchAll and others.

The ideal implementation will allow you to write something like

val username: Type = ...
val now: Date = new Date()
crud.searchAll[User](("username" equals username) &&
                     ("expiryDate" lessThan now))
cpcundill commented 11 years ago

+1

fommil commented 11 years ago

This would be best implemented as a DSL to create Spray JSON JsValue instances, which are then serialised to DBObject. Also, side effect is: DSL for Spray JSON :-)

fommil commented 11 years ago

@janm399 ! Comment()

This could be awesome... your code can be entirely independent of ScalaD and it'll still work like a charm. i.e. if this

("username" equals username) &&
                     ("expiryDate" lessThan now)

were converted into a JsObject that looked like

{
  "username": USERNAME,
  "expiryDate": {"$lt": NOW}
}

where USERNAME and NOW are JsObjects obtained from the relevant JsonFormat. (USERNAME is trivial here, but NOW will be our custom Date type that is auto-converted into a MongoDB DateFormat by the serialised)

and also, if we're wanting to do things like findModify it is a simple case of extending the CRUD traits to take in more DBObjects that we'll implicitly convert from the DSL :-)

adinapoli commented 11 years ago

I know I'm not working on the project, but I couldn't resist to chime in :D I like Sam's idea, I think could be the more scalaDble (pun intended) approach: If you guys work on a DSL / Implicit system to convert that kind of expression to valid JsObject you will have free queries, because if things aren't changed I remember you can pass a JsObject to do queries, and so you are in business :P

janm399 commented 11 years ago

@adinapoli You're more than welcome to chip in any time; I'd love to have contributions and ideas. I'll sketch out my DSL this AM.

fommil commented 11 years ago

@janm399 sweeet - is it a Spray JSON builder?