Added support for "IN" operator of a WHERE clause.
The table update only allowed for "==" operator as in: UPDATE mytable SET foo = 'bar' WHERE id = 123; Now allows for "IN" operator as in: UPDATE mytable SET foo = 'bar' WHERE id IN (123, 876); This required changes to the "_args_to_clause" and "update" functions.
This commit is contained in:
parent
4f3f574d58
commit
fffa633e84
@ -121,6 +121,13 @@ class Table(object):
|
|||||||
if not len(keys):
|
if not len(keys):
|
||||||
return False
|
return False
|
||||||
clause = [(u, row.get(u)) for u in keys]
|
clause = [(u, row.get(u)) for u in keys]
|
||||||
|
"""
|
||||||
|
Don't update the key itself, so remove any keys from the row dict
|
||||||
|
"""
|
||||||
|
for key in keys:
|
||||||
|
if key in row.keys():
|
||||||
|
del row[key]
|
||||||
|
|
||||||
if ensure:
|
if ensure:
|
||||||
self._ensure_columns(row, types=types)
|
self._ensure_columns(row, types=types)
|
||||||
try:
|
try:
|
||||||
@ -180,6 +187,9 @@ class Table(object):
|
|||||||
self._ensure_columns(args)
|
self._ensure_columns(args)
|
||||||
clauses = []
|
clauses = []
|
||||||
for k, v in args.items():
|
for k, v in args.items():
|
||||||
|
if isinstance(v, list) or isinstance(v, tuple):
|
||||||
|
clauses.append(self.table.c[k].in_(v))
|
||||||
|
else:
|
||||||
clauses.append(self.table.c[k] == v)
|
clauses.append(self.table.c[k] == v)
|
||||||
return and_(*clauses)
|
return and_(*clauses)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user