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

Implement convenient DSL for DBObject #51

Open
janm399 opened this issue Feb 7, 2013 · 6 comments
Open

Implement convenient DSL for DBObject #51

janm399 opened this issue Feb 7, 2013 · 6 comments
Assignees
Milestone

Comments

@janm399
Copy link
Member

janm399 commented Feb 7, 2013

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
Copy link

+1

@fommil
Copy link
Contributor

fommil commented Feb 7, 2013

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
Copy link
Contributor

fommil commented Feb 7, 2013

@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
Copy link
Contributor

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
Copy link
Member Author

janm399 commented Feb 8, 2013

@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
Copy link
Contributor

fommil commented Feb 8, 2013

@janm399 sweeet - is it a Spray JSON builder?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants