I want to create an SQL query by concatenating strings but with conditions.
qs_str= 'Select *, from items ...'
The conditions:
if active:
qs_str = ' '.join([qs_str, f'WHERE active=true'])
if is_parent:
qs_str = ' '.join([qs_str, f'WHERE parent=true'])
if limit:
qs_str = ' '.join([qs_str, f'WHERE LIMIT={limit}'])
.....
There is not really a fixed limit on how many conditions will be.
The issue is the WHERE clause, should be added only once(or not if there is no condition) and how to add AND, to know if a condition is already in place.
Because there is no theoretically limit for the number of conditions I can't
using combinatorics ifs like(if is_active and is_parent) is not a solution.