added __or and __and to sql query generator
This commit is contained in:
parent
b3afee2f86
commit
1d126913e9
1 changed files with 6 additions and 1 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue