aws / aws-sdk-ruby-record

Official repository for the aws-record gem, an abstraction for Amazon DynamoDB.
Apache License 2.0
318 stars 41 forks source link

Conditional put #41

Open goozler opened 7 years ago

goozler commented 7 years ago

Hi! Is there any way to do a conditional put request? The case when I get some data, change it by some operations and I want to save it back only if data in DynamoDB still the same when I get it.

Maybe you could give me an advice how to implement it with a few changes.

awood45 commented 7 years ago

#save doesn't yet expose this functionality, but i think it should. The tricky part is how we want to expose the condition expression. I'm going to chew on this a bit - one possible option that solves this generically is maybe an :override_parameters option that is passed in to save, that lets you override any of the underlying client parameters. In this manner, you could provide conditional expressions, or for that matter, alter any other underlying client option if you know what you're doing. It wouldn't preclude other params that do this in a higher level way either.

awood45 commented 7 years ago

Okay, after some discussions, I think the plan will be to expose select parameters individually (override parameters causes nasty collision issues with existing helper functionality).

For example, you could append to existing conditions, and the condition expression would look kind of like:

"#{aws_record_condition_expression} AND (#{user_provided_condition_expression})"

..and then we would merge the expression attribute name and value hashes.

jmclachlan commented 6 years ago

Any update on this?

awood45 commented 5 years ago

We're going to work this in with smart query/scan support that I'm working on.