如何动态构建 query,
有时候要写个 demo server,所以用了 tinydb 这个库,但是有一个问题,如何动态构造 query 呢?
querys = []
for name in ("a", "b","c", "d"):
val = self.get_argument(name,"")
if val:
querys.append(where(name)==val)
list=db.search(querys)
有没有了办法实现上面那种效果呢?
1
nbboy 2018-05-28 17:19:31 +08:00 1
太小众了把。
|
2
louisganlu 2018-05-30 16:09:39 +08:00 1
http://tinydb.readthedocs.io/en/latest/usage.html
The second, traditional way of constructing queries is as follows: >>> from tinydb import where >>> db.search(where('field') == 'value') Using where('field') is a shorthand for the following code: >>> db.search(Query()['field'] == 'value') Accessing nested fields with this syntax can be achieved like this: >>> db.search(where('birthday').year == 1900) >>> db.search(where('birthday')['year'] == 1900) |