aws-record 2.12.0 → 2.13.1

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: fe251cd0c7fc4eabda02c7d02e0f68443027b21bf925733badf8f8fd7c8540e2
4
+ data.tar.gz: 6107ea30546f5fb894a9f963b184b5414b1e6d6e0c6e073c57acfdaaf31c94fb
5
5
  SHA512:
6
- metadata.gz: 8b54ae2d2834b31a7fcb32e62e5aab25966ff30fa5fe34b8fe4797507e8a99a37f42eeeb4910e2950f214c07af30f2ec9ea532820ff1ef56569fd17912c803e3
7
- data.tar.gz: 957101a0f8ad105a613e3b2c33b5f2d3999ebf00bcb83ed0142008ebf213fde862aab433b4eca0403c2b932c35abf7fefc074be2051648e42ecdfda2cf1bbc9f
6
+ metadata.gz: 2f67f857fe7837e662b05ba74f040fb0460275596981b0100edae2efd92349828f129a9836e7a0c2551efd8e2330da4175e3ae61a3d4bfa45a059ef94da4cb5a
7
+ data.tar.gz: c75497be6b3f37fa84f65267f58bc098cdbc86ec08bdb6be549fe5407035582d797d2cc7e43eec5ff8d7c7b5f248a36b7939505dac4f89fc6b2149c951038234
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ 2.13.1 (2024-07-18)
2
+ ------------------
3
+
4
+ * Issue - Do not try to hydrate undeclared attributes from storage on `batch_read`. (#139)
5
+
6
+ 2.13.0 (2023-10-17)
7
+ ------------------
8
+
9
+ * Feature - Allow custom `update_expression` to be passed through to the
10
+ underlying client calls. (#137)
11
+
1
12
  2.12.0 (2023-09-28)
2
13
  ------------------
3
14
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.12.0
1
+ 2.13.1
@@ -173,6 +173,9 @@ module Aws
173
173
  new_item_opts = {}
174
174
  item.each do |db_name, value|
175
175
  name = item_class.attributes.db_to_attribute_name(db_name)
176
+
177
+ next unless name
178
+
176
179
  new_item_opts[name] = value
177
180
  end
178
181
  item = item_class.new(new_item_opts)
@@ -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
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'ostruct'
4
+
3
5
  module Aws
4
6
  module Record
5
7
  module Transactions
@@ -284,25 +286,17 @@ module Aws
284
286
  def _transform_update_record(update_record, opts)
285
287
  # extract dirty attribute changes to perform an update
286
288
  opts[:table_name] = update_record.class.table_name
289
+ opts[:key] = update_record.send(:key_values)
287
290
  dirty_changes = update_record.send(:_dirty_changes_for_update)
288
- update_tuple = update_record.class.send(
291
+ update_expression_opts = update_record.class.send(
289
292
  :_build_update_expression,
290
293
  dirty_changes
291
294
  )
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
295
+ opts = update_record.class.send(
296
+ :_merge_update_expression_opts,
297
+ update_expression_opts,
298
+ opts
299
+ )
306
300
  { update: opts }
307
301
  end
308
302
 
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.1
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: 2024-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-dynamodb
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubygems_version: 3.4.10
96
+ rubygems_version: 3.5.5
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: AWS Record library for Amazon DynamoDB