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

Support for custom Update expressions #137

Closed
lsglick opened this issue Oct 11, 2023 · 2 comments · Fixed by #138
Closed

Support for custom Update expressions #137

lsglick opened this issue Oct 11, 2023 · 2 comments · Fixed by #138
Labels
feature-request A feature should be added or improved.

Comments

@lsglick
Copy link
Contributor

lsglick commented Oct 11, 2023

Occasionally we would like to use Update expressions for more advanced updates than seem to be available when modifying an attribute and using the existing #update methods. We particularly need this for transactions.

For example:

  • Use ADD/DELETE to modify items in a set
  • Use if_not_exists function to control behavior when multiple updates occur in succession
  • Accumulate a value during a transaction (similar to increment! but in a transaction)

It would be great if there were a way to do this in special cases while still largely taking advantages of the conveniences afforded by this SDK.

Unfortunately, update_expression is always set directly with no opportunity to override it.

E.g. Item Operations:
https://github.com/aws/aws-sdk-ruby-record/blob/92e0070eea16698e23be8e31d3a36e681dc079e9/lib/aws-record/record/item_operations.rb#L609

E.g. Transactions:
https://github.com/aws/aws-sdk-ruby-record/blob/92e0070eea16698e23be8e31d3a36e681dc079e9/lib/aws-record/record/transactions.rb#L294

Some potential ideas:

  • If update_expression is passed in opts, use it instead of a generated one.
  • If update_expression is passed in opts, merge it with the generated one (might need to combine with the generated SET/REMOVE clauses)
  • A way to pass-through raw update clauses to Aws::Record::Transactions.transact_write that only set the minimal key/table rather than the full transformation (similar to delete).
  • A way to generate more raw actions similar to #transact_check_expression.

Thanks!

@mullermp mullermp added the feature-request A feature should be added or improved. label Oct 11, 2023
@mullermp
Copy link
Contributor

Thanks for opening an issue. Tagging as a feature request. I am happy to review any pull requests if you have bandwidth. I recently plumbed through some options to save and update. I think option 1 (using opts, generally, over default values) is reasonable and I'd like to see that throughout item_operations and transactions usage.

lsglick added a commit to lsglick/aws-sdk-ruby-record that referenced this issue Oct 14, 2023
…changes

This is a minimal implementation to allow update expressions to be passed through directly to the api call. To avoid conflicts, an error is raised if an update expression would have been generated by the sdk to update dirty attributes.

Also: Adds support for pass-through API options to the class-level `.update` item operation.

Resolves aws#137
@lsglick
Copy link
Contributor Author

lsglick commented Oct 14, 2023

@mullermp I took a pass at it in #138. Let me know what you think!

There's a bit of logic duplication, but I was mostly trying to following existing structure in the repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved.
Projects
None yet
2 participants