Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jpinner-lyft committed Oct 13, 2017
1 parent 8766fb5 commit 9b01c78
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions examples/model.py
Expand Up @@ -167,37 +167,32 @@ class Meta:

# DynamoDB will update the item, by adding 1 to the views attribute,
# if the forum_name attribute equals 'Some Forum' or the subject attribute exists
print(thread_item.update_item(
'views',
1,
action='add',
condition=((Thread.forum_name == 'Some Forum') | Thread.subject.exists())
print(thread_item.update(
actions=[
Thread.views.add(1)
],
condition=(
(Thread.forum_name == 'Some Forum') | Thread.subject.exists()
)
))

# DynamoDB will atomically update the attributes `replies` (increase value by 1),
# and `last_post_datetime` (set value to the current datetime)
print(thread_item.update({
'replies': {
'action': 'add',
'value': 1,
},
'last_post_datetime': {
'action': 'put',
'value': datetime.now(),
},
}))
print(thread_item.update(actions=[
Thread.replies.add(1),
Thread.last_post_datetime.set(datetime.now()),
]))

# DynamoDB will delete the item, only if the views attribute is equal to one
try:
print(thread_item.delete(Thread.views == 1))
except:
pass

# Delete an item's attribute
print(thread_item.update_item(
'tags',
action='delete'
))
# Remove an item's attribute
print(thread_item.update(actions=[
Thread.tags.remove()
]))

# Backup/restore example
# Print the size of the table
Expand Down

0 comments on commit 9b01c78

Please sign in to comment.