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: else:
raise ValueError(f"{col} requires a list, set or string as constraint value.") raise ValueError(f"{col} requires a list, set or string as constraint value.")
continue continue
elif key.endswith('__any'): elif key.endswith('__any') or key.endswith('__or'):
where, subvalues = constraints_to_sql(constraint, ' OR ', key+tag+'_') where, subvalues = constraints_to_sql(constraint, ' OR ', key+tag+'_')
sql.append(f'({where})') sql.append(f'({where})')
values.update(subvalues) values.update(subvalues)
continue 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}') sql.append(f'{col} {op} :{prepend_key}{key}{tag}')
values[prepend_key+key+tag] = constraint values[prepend_key+key+tag] = constraint
return joiner.join(sql) if sql else '', values return joiner.join(sql) if sql else '', values