3 ms·
That's what the fancier __init__() at the end of the article[1] is for :) Here's the tl;dr of a real-world example[2]: query = Query().SELECT(...).WHERE(.
by genericlemon24 5y ago
That's what the fancier __init__() at the end of the article[1] is for :)
Here's the tl;dr of a real-world example[2]:
query = Query().SELECT(...).WHERE(...)
for subtags in tags:
tag_query = BaseQuery({'(': [], ')': ['']}, {'(': 'OR'})
tag_add = partial(tag_query.add, '(')
for subtag in subtags:
tag_add(subtag)
query.WHERE(str(tag_query))
It can be shortened by making a special subclass, but I only needed this once or twice so I didn't bother yet:
for subtags in tags:
tag_query = QList('OR')
for subtag in subtags:
tag_query.append(subtag)
query.WHERE(str(tag_query))
[1]: https://death.andgravity.com/query-builder-how#more-init https://death.andgravity.com/query-builder-how#more-init
[2]: https://github.com/lemon24/reader/blob/10ccabb9186f531da04db91ee24ba63abc9e4318/src/reader/_storage.py#L1311-L1356 https://github.com/lemon24/reader/blob/10ccabb9186f531da04db...