dmpayton / reqon

Build simple, read-only RethinkDB queries from JSON
https://reqon.readthedocs.org/
MIT License
2 stars 1 forks source link

Query ordering #3

Open dphaener opened 8 years ago

dphaener commented 8 years ago

When constructing a ReQL query, ordering is important. For instance, this query will run fine:

{
  '$schema': 'movies',
  '$query': [
    ['$filter', ['rank', ['$gt', 8]]],
    ['$count']
  ]
}

But this will not:

{
  '$schema': 'movies',
  '$query': [
    ['$count'],
    ['$filter', ['rank', ['$gt', 8]]]
  ]
}

There needs to be a sensible way to ensure that the query items are parsed and appended in the appropriate order.

dphaener commented 8 years ago

As previously discussed, a possible implementation would look like this:

Have an ordered list of query operators:

["$between", "$order_by", "$filter"]

We can then use that list to process the operators in the proper order. We can also accept a top level item on the query object to allow custom operator ordering, and use that list instead:

{
  "$table":"movies",
  "$operator_order":["$order_by", "$between", "$filter"],
  "$query": []
}

This does raise the question though, what if all operators aren't passed into the custom array. My initial thought would be to just append those last, after all others are appended in the proper order.