0.0
No commit activity in last 3 years
No release in over 3 years
Use JSON and Hashes to create complex queries on your DM models.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme
Search your models with JSON!
=============================

How to use
----------

gem install gemcutter          # unless you already have
gem tumble                     # unless you already have
gem install dm-json-search

Wala:

Book.all_from_json('[{"eql":{"Book.title":"Psycho"}}]')
# Should this be mixed in automagically to every model?


Another example query and it's json
-----------------------------------

puts Ticket.select { |t| 
  t.title == "foo" || (t.user_id == 6 && t.account_id == 9) 
}.query.to_json

Becomes:

{
    "model": "Ticket",
    "repository": "default",
    "conditions": {
        "and": [{
            "or": [{
                "eql": { "Ticket.title": "foo" }
            },
            {
                "and": [{
                    "eql": { "Ticket.user_id": 6 }
                },
                {
                    "eql": { "Ticket.account_id": 9 }
                }]
            }]
        }]
    },
    "reload": false,
    "order": ["Ticket.id.asc"],
    "fields": [...],
    "links": [], // these don't work yet
    "unique": false,
    "limit": null,
    "offset": 0
}


Explanation
-----------

Operations are objects with a key for the Operation#slug and an array of operands. Comparisons are object with a key for the Comparison#slug and an object with a property key and a value for the comparison.

So, you can send in a huge json string like the above, or you can just send in the conditions part: { "and": [...] }. Or, if you just send in an array, it will wrap that array in an "and" hash.

All DM Operations and Conditions are permitted on any Property of any Model. This probably needs to be changed to only search some fields.


TODO
----

* Spec it out and make sure there are no vectors for destructive actions
* Make links work
* Make it better?