added __or and __and to sql query generator

This commit is contained in:
Lex Berezhny 2019-05-16 01:34:54 -04:00
parent b3afee2f86
commit 1d126913e9

View file

@ -131,11 +131,16 @@ def constraints_to_sql(constraints, joiner=' AND ', prepend_key=''):
else:
raise ValueError(f"{col} requires a list, set or string as constraint value.")
continue
elif key.endswith('__any'):
elif key.endswith('__any') or key.endswith('__or'):
where, subvalues = constraints_to_sql(constraint, ' OR ', key+tag+'_')
sql.append(f'({where})')
values.update(subvalues)
continue
elif key.endswith('__and'):
where, subvalues = constraints_to_sql(constraint, ' AND ', key+tag+'_')
sql.append(f'({where})')
values.update(subvalues)
continue
sql.append(f'{col} {op} :{prepend_key}{key}{tag}')
values[prepend_key+key+tag] = constraint
return joiner.join(sql) if sql else '', values