有使用过 Python tinydb 这个库的吗,求助

如何动态构建 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)

有没有了办法实现上面那种效果呢?


有使用过 Python tinydb 这个库的吗,求助

3 回复

帖子内容呢?没内容我怎么帮你?


太小众了把。

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)

回到顶部