Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unless_exists example in README.md #660

Merged
merged 4 commits into from
May 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Refactor AWS plugin and don't send excessive Exist: true attribute …
…to ensure an item with specified partition key exists
andrykonchin committed May 27, 2023
commit 464f115b56c2730aa9bc6cbdace4f2c89168bfbc
5 changes: 1 addition & 4 deletions lib/dynamoid/adapter_plugin/aws_sdk_v3.rb
Original file line number Diff line number Diff line change
@@ -631,10 +631,7 @@ def expected_stanza(conditions = nil)
conditions.delete(:unless_exists).try(:each) do |col|
expected[col.to_s][:exists] = false
end
conditions.delete(:if_exists).try(:each) do |col, val|
expected[col.to_s][:exists] = true
expected[col.to_s][:value] = val
end

conditions.delete(:if).try(:each) do |col, val|
expected[col.to_s][:value] = val
end
4 changes: 2 additions & 2 deletions lib/dynamoid/persistence/save.rb
Original file line number Diff line number Diff line change
@@ -89,8 +89,8 @@ def options_to_update_item
end

conditions = {}
conditions[:if_exists] ||= {}
conditions[:if_exists][@model.class.hash_key] = @model.hash_key
conditions[:if] ||= {}
conditions[:if][@model.class.hash_key] = @model.hash_key

# Add an optimistic locking check if the lock_version column exists
if @model.class.attributes[:lock_version]
4 changes: 2 additions & 2 deletions lib/dynamoid/persistence/update_fields.rb
Original file line number Diff line number Diff line change
@@ -54,8 +54,8 @@ def options_to_update_item
end

conditions = @conditions.deep_dup
conditions[:if_exists] ||= {}
conditions[:if_exists][@model_class.hash_key] = @partition_key
conditions[:if] ||= {}
conditions[:if][@model_class.hash_key] = @partition_key
options[:conditions] = conditions

options