Idea
Now we have limits in Datastore to select data with filter() only by one
property with "not equal" operation (<,<=,>,>=,!=).
This code does not work on Google App Engine datastore:
apartment = Apartment.all().filter("rooms>=", 2).filter("cost<", 50000)
This new feature will allow to make queries similar with on relational
databases for select data by more that one criteria, if we have used "not
equal" operation by more that one property.
Recommendations
In many cases we have used small range of values. For example:
* age: from 1 to 120
* floor: from 1 to 50
* rooms: from 1 to 20
* etc
Yes, we also have a large ranges. For example:
* cost: from 0.01 to unlimited
* comments count: from 0 to unlimited
* page views: from 0 to unlimited
* ect
For select data from large ranges - you need use only one available filter
allowed for use with Datastore.
But, more interest that for small ranges we can create additional columns,
where we can save computed value. We can use this additional properties in our
filters() by emulate real filtering.
EXAMPLE: select apartments
We can do this:
apartment = Apartment.all().filter("rooms>=", 2).filter("cost<", 50000)
And, our filter() implementation translate this to:
apartment = Apartment.all().filter("rooms__ge", 2).filter("cost<", 50000)
Really, we replace all operation with "small range" property to appropriate
computed property name. In our case we have next additional properties for each
"small range":
* <property_name>__gt - ">"
* <property_name>__ge - ">="
* <property_name>__lt - "<"
* <property_name>__le - "<="
* <property_name>__ne - "!="
We have a property "rooms" with value "5".
Our Apartment object stored in datastore have the next computed properties:
* rooms__gt = [6,7,8,9,...,50]
* rooms__ge = [5,6,7,8,...,50]
* rooms__lt = [1,2,3,4]
* rooms__le = [1,2,3,4,5]
* rooms__ne = [1,2,3,4,6,7,8,...,50]
Please check if this is correct. If you have any propositions - tell me about
this in this issue.
See also
* http://www.google.com/events/io/2010/sessions/next-gen-queries-appengine.html
* http://docs.python.org/reference/datamodel.html#object.__lt__
Original issue reported on code.google.com by anton.danilchenko on 26 Jan 2011 at 9:25
Original issue reported on code.google.com by
anton.danilchenko
on 26 Jan 2011 at 9:25