Skip to content

Commit

Permalink
Remove removed use cases from README_transact.md
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed Oct 28, 2024
1 parent b63bfad commit 851be13
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions README_transact.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,15 @@ end
```

### Update items
An item can be updated by providing the hash key, range key if applicable, and the fields to update.
Updating fields can also be done within a block using the `set()` method.
To increment a numeric value or to add values to a set use `add()` within the block.
Similarly a field can be removed or values can be removed from a set by using `delete()` in the block.
An item can be updated by providing a model or hash key and range key if applicable, and the fields to update.
```ruby
Dynamoid::TransactionWrite.execute do |txn|
# sets the name and title for user 1
# The user is found by id
txn.update!(User, id: 1, name: 'bob', title: 'mister')

# sets the name, increments a count and deletes a field
txn.update!(user) do |u| # a User instance is provided
u.set(name: 'bob')
u.add(article_count: 1)
u.delete(:title)
end
# change name and title for a user
txn.update_attributes!(user, name: 'bob', title: 'mister')

# adds to a set of integers and deletes from a set of strings
txn.update!(User, id: 3) do |u|
u.add(friend_ids: [1, 2])
u.delete(child_names: ['bebe'])
end
# sets the name and title for a user
# The user is found by id (that equals 1)
txn.update_fields!(User, 1, name: 'bob', title: 'mister')
end
```

Expand Down

0 comments on commit 851be13

Please sign in to comment.