Currently the RestAPI only support the and (&) operator and the nor operator. The syntax ir
https://..../{tablename}?{field1}.{op1}=value1&{field2}.{op2}=value2¬.{field3}.{op3}=value3
where op can be one of eq, ne, lt, gt, le, ge, startwith, in, contains.
It is intentionally designed to not allow arbitrary queries since it can result in ddos attacks.
If you do want arbitrary queries you can do:
db.define_table(
"thing",
Field("name"))
from pydal.querybuilder import QueryBuilder
@action("search/<tablename>")
@action.uses(auth)
def search(tablename):
# maybe if not auth.user_id: raise HTTP(403)
# maybe if not tablename in allowed_tables: raise HTTP(403)
if not tablename in db: raise HTTP(400)
table = db[tablename]
builder = QueryBuilder(table)
try:
query = builder.parse(request.GET.get("q", ""))
items = db(query).select().as_list()
except:
return HTTP(400)
return {"items": items}
This allows arbitrary searches like
search/thing?q=name is Max or (name is Tim and id > 1) or name contains x
The RestAPI is designed for simple structured queries with the ability to manipulate the format of the respose.
The QueryBuilder is designed to build an arbitrary query from a string.
Perhaps there should a superset of both but I am not convinced there is one solution that will make everybody happy without add even more magic and complexity.