A base query object.
This object serves as a layer to decouple a query from the web in the form of query-string args into an internal object which rum.interfaces.IRepository use to filter the collection of objects.
It is the responsability of the rum.interfaces.IRepository to translate this object into a query the underlying data backend undersands.
Parameters
Examples:
>>> # A simple query: "name == Alberto"
>>> q = Query(eq('name', 'Alberto'))
>>> q
Query(eq('name', 'Alberto'), None, None, None, ())
>>> # Get a query string
>>> q.as_qs()
'q.o=eq&q.a=Alberto&q.c=name'
>>> # A query can be converted to a urlencodable dict and back
>>> Query.from_dict(q.as_dict())
Query(eq('name', 'Alberto'), None, None, None, ())
>>> # A more complex query: "name == 'Alberto' and (20 < age < 30)" with
>>> # sorting criteria, offset and limit
>>> q = Query(and_([eq('name', 'Alberto'), or_([gt('age', 20), lt('age', 30)])]), [desc('join_date')], 10, 10)
>>> q
Query(and_([eq('name', 'Alberto'), or_([gt('age', 20), lt('age', 30)])]), [desc('join_date')], 10, 10, ())
>>> Query.from_dict(q.as_dict())
Query(and_([eq('name', 'Alberto'), or_([gt('age', 20), lt('age', 30)])]), [desc('join_date')], 10, 10, ())
“ands” an expression to this Query’s expression returning a new Query.
Negates arg1
A boolean AND of all arguments
arg1 is greater than arg2
arg1 is null
arg1 is equal to
arg1 is in arg2 (which should be a sequence)
arg1 is greater than or equal arg2
arg1 contains arg2
arg1 is less than arg2
arg 1 is not equal to
arg1 starts with arg2
A boolean OR of all arguments
arg1 is not null
This is a basic expression to build up queries.
Descending ordering criteria.
Example, order in descending order by attribute age:
>>> desc('age')
desc('age')
Ascending ordering criteria.
Example, order in ascending order by attribute name:
>>> asc('name')
asc('name')
arg1 ends with arg2
arg1 is less than or equal arg2