Add basic support for AttributeUpdates in Dynamo update_item. Closes #449.

This commit is contained in:
Steve Pulec 2015-11-07 16:45:24 -05:00
commit 8d41d0019b
3 changed files with 47 additions and 4 deletions

View file

@ -121,6 +121,14 @@ class Item(object):
# TODO deal with other types
self.attrs[key] = DynamoType({"S": value})
def update_with_attribute_updates(self, attribute_updates):
for attribute_name, update_action in attribute_updates.items():
action = update_action['Action']
new_value = update_action['Value'].values()[0]
if action == 'PUT':
# TODO deal with other types
self.attrs[attribute_name] = DynamoType({"S": new_value})
class Table(object):
@ -411,12 +419,19 @@ class DynamoDBBackend(BaseBackend):
return table.scan(scan_filters)
def update_item(self, table_name, key, update_expression):
def update_item(self, table_name, key, update_expression, attribute_updates):
table = self.get_table(table_name)
if table.hash_key_attr in key:
# Sometimes the key is wrapped in a dict with the key name
key = key[table.hash_key_attr]
hash_value = DynamoType(key)
item = table.get_item(hash_value)
item.update(update_expression)
if update_expression:
item.update(update_expression)
else:
item.update_with_attribute_updates(attribute_updates)
return item
def delete_item(self, table_name, keys):