aws-record 2.12.0 → 2.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffc6a505faafd948f6bd7a553ebd1a6c75ff48d0d77df4b80c2eaae7c550d851
4
- data.tar.gz: 0721314ff3f6755de1174c494f6d4f9b7b848db2c47106d721ba0458c438aa0f
3
+ metadata.gz: 4101d86e9fc3c9644b701a42e3ff48c09a24f60169d5d1c0d6cd9aced0ff8e64
4
+ data.tar.gz: d672cbe2ab1b4e8b27749729fe0810684501a564893f6cc2d704e63581dfe53f
5
5
  SHA512:
6
- metadata.gz: 8b54ae2d2834b31a7fcb32e62e5aab25966ff30fa5fe34b8fe4797507e8a99a37f42eeeb4910e2950f214c07af30f2ec9ea532820ff1ef56569fd17912c803e3
7
- data.tar.gz: 957101a0f8ad105a613e3b2c33b5f2d3999ebf00bcb83ed0142008ebf213fde862aab433b4eca0403c2b932c35abf7fefc074be2051648e42ecdfda2cf1bbc9f
6
+ metadata.gz: d63848749ec893de308eb3e97e3131b6479d0f4781f1277ac14f4dbbeed0a6fdb6237546ba881f41448c1c5933d00a960c25091af8e85cbb768bf5560d4c3d89
7
+ data.tar.gz: f4feb5e0f1c6199945cb18cbfd3ca9a61344c795643aba58ec73a958dc0b315365bc82632e31eced2a2ada684b635e6fead8ef4995ae7b5c4babc46802d137fb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ 2.13.0 (2023-10-17)
2
+ ------------------
3
+
4
+ * Feature - Allow custom `update_expression` to be passed through to the
5
+ underlying client calls. (#137)
6
+
1
7
  2.12.0 (2023-09-28)
2
8
  ------------------
3
9
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.12.0
1
+ 2.13.0
@@ -60,6 +60,13 @@ module Aws
60
60
  # the key existance check yourself in your condition expression if you
61
61
  # wish to do so.
62
62
  class TransactionalSaveConditionCollision < RuntimeError; end
63
+
64
+ # Raised when you attempt to combine your own update expression with
65
+ # the update expression auto-generated from updates to an item's
66
+ # attributes. The path forward until this case is supported is to
67
+ # perform attribute updates yourself in your update expression if you
68
+ # wish to do so.
69
+ class UpdateExpressionCollision < RuntimeError; end
63
70
  end
64
71
  end
65
72
  end
@@ -269,27 +269,22 @@ module Aws
269
269
  )
270
270
  end
271
271
  else
272
+ update_opts = {
273
+ table_name: self.class.table_name,
274
+ key: key_values
275
+ }
272
276
  update_pairs = _dirty_changes_for_update
273
- update_tuple = self.class.send(
277
+ update_expression_opts = self.class.send(
274
278
  :_build_update_expression,
275
279
  update_pairs
276
280
  )
277
- if update_tuple
278
- uex, exp_attr_names, exp_attr_values = update_tuple
279
- update_opts = {
280
- table_name: self.class.table_name,
281
- key: key_values,
282
- update_expression: uex,
283
- expression_attribute_names: exp_attr_names
284
- }
285
- update_opts[:expression_attribute_values] = exp_attr_values unless exp_attr_values.empty?
286
- else
287
- update_opts = {
288
- table_name: self.class.table_name,
289
- key: key_values
290
- }
291
- end
292
- dynamodb_client.update_item(opts.merge(update_opts))
281
+ opts = self.class.send(
282
+ :_merge_update_expression_opts,
283
+ update_expression_opts,
284
+ opts
285
+ )
286
+ resp = dynamodb_client.update_item(opts.merge(update_opts))
287
+ assign_attributes(resp[:attributes]) if resp[:attributes]
293
288
  end
294
289
  data = instance_variable_get('@data')
295
290
  data.destroyed = false
@@ -581,19 +576,21 @@ module Aws
581
576
  # Aws::DynamoDB::Client#update_item} call immediately on the table,
582
577
  # using the attribute key/value pairs provided.
583
578
  #
584
- # @param [Hash] opts attribute-value pairs for the update operation you
585
- # wish to perform. You must include all key attributes for a valid
579
+ # @param [Hash] new_params attribute-value pairs for the update operation
580
+ # you wish to perform. You must include all key attributes for a valid
586
581
  # call, then you may optionally include any other attributes that you
587
582
  # wish to update.
583
+ # @param [Hash] opts Options to pass through to the
584
+ # {http://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#update_item-instance_method
585
+ # Aws::DynamoDB::Client#update_item} call.
588
586
  #
589
587
  # @raise [Aws::Record::Errors::KeyMissing] if your option parameters do
590
588
  # not include all table keys.
591
- def update(opts)
589
+ def update(new_params, opts = {})
592
590
  key = {}
593
591
  @keys.keys.each_value do |attr_sym|
594
- unless (value = opts.delete(attr_sym))
595
- raise Errors::KeyMissing, "Missing required key #{attr_sym} in #{opts}"
596
-
592
+ unless (value = new_params.delete(attr_sym))
593
+ raise Errors::KeyMissing, "Missing required key #{attr_sym} in #{new_params}"
597
594
  end
598
595
 
599
596
  attr_name = attributes.storage_name_for(attr_sym)
@@ -603,14 +600,9 @@ module Aws
603
600
  table_name: table_name,
604
601
  key: key
605
602
  }
606
- update_tuple = _build_update_expression(opts)
607
- unless update_tuple.nil?
608
- uex, exp_attr_names, exp_attr_values = update_tuple
609
- update_opts[:update_expression] = uex
610
- update_opts[:expression_attribute_names] = exp_attr_names
611
- update_opts[:expression_attribute_values] = exp_attr_values unless exp_attr_values.empty?
612
- end
613
- dynamodb_client.update_item(update_opts)
603
+ update_expression_opts = _build_update_expression(new_params)
604
+ opts = _merge_update_expression_opts(update_expression_opts, opts)
605
+ dynamodb_client.update_item(opts.merge(update_opts))
614
606
  end
615
607
 
616
608
  private
@@ -641,10 +633,22 @@ module Aws
641
633
  update_expressions = []
642
634
  update_expressions << ("SET #{set_expressions.join(', ')}") unless set_expressions.empty?
643
635
  update_expressions << ("REMOVE #{remove_expressions.join(', ')}") unless remove_expressions.empty?
644
- if update_expressions.empty?
645
- nil
646
- else
647
- [update_expressions.join(' '), exp_attr_names, exp_attr_values]
636
+ {
637
+ update_expression: update_expressions.join(' '),
638
+ expression_attribute_names: exp_attr_names,
639
+ expression_attribute_values: exp_attr_values
640
+ }.reject { |_, value| value.nil? || value.empty? }
641
+ end
642
+
643
+ def _merge_update_expression_opts(update_expression_opts, pass_through_opts)
644
+ update_expression_opts.merge(pass_through_opts) do |key, expression_value, pass_through_value|
645
+ case key
646
+ when :update_expression
647
+ msg = 'Using pass-through update expression with attribute updates is not supported.'
648
+ raise Errors::UpdateExpressionCollision, msg
649
+ else
650
+ expression_value.merge(pass_through_value)
651
+ end
648
652
  end
649
653
  end
650
654
 
@@ -284,25 +284,17 @@ module Aws
284
284
  def _transform_update_record(update_record, opts)
285
285
  # extract dirty attribute changes to perform an update
286
286
  opts[:table_name] = update_record.class.table_name
287
+ opts[:key] = update_record.send(:key_values)
287
288
  dirty_changes = update_record.send(:_dirty_changes_for_update)
288
- update_tuple = update_record.class.send(
289
+ update_expression_opts = update_record.class.send(
289
290
  :_build_update_expression,
290
291
  dirty_changes
291
292
  )
292
- uex, exp_attr_names, exp_attr_values = update_tuple
293
- opts[:key] = update_record.send(:key_values)
294
- opts[:update_expression] = uex
295
- # need to combine expression attribute names and values
296
- opts[:expression_attribute_names] = if (names = opts[:expression_attribute_names])
297
- exp_attr_names.merge(names)
298
- else
299
- exp_attr_names
300
- end
301
- opts[:expression_attribute_values] = if (values = opts[:expression_attribute_values])
302
- exp_attr_values.merge(values)
303
- else
304
- exp_attr_values
305
- end
293
+ opts = update_record.class.send(
294
+ :_merge_update_expression_opts,
295
+ update_expression_opts,
296
+ opts
297
+ )
306
298
  { update: opts }
307
299
  end
308
300
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-record
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.0
4
+ version: 2.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amazon Web Services
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-28 00:00:00.000000000 Z
11
+ date: 2023-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-dynamodb