aws-record 2.12.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/VERSION +1 -1
- data/lib/aws-record/record/errors.rb +7 -0
- data/lib/aws-record/record/item_operations.rb +39 -35
- data/lib/aws-record/record/transactions.rb +7 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4101d86e9fc3c9644b701a42e3ff48c09a24f60169d5d1c0d6cd9aced0ff8e64
|
4
|
+
data.tar.gz: d672cbe2ab1b4e8b27749729fe0810684501a564893f6cc2d704e63581dfe53f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d63848749ec893de308eb3e97e3131b6479d0f4781f1277ac14f4dbbeed0a6fdb6237546ba881f41448c1c5933d00a960c25091af8e85cbb768bf5560d4c3d89
|
7
|
+
data.tar.gz: f4feb5e0f1c6199945cb18cbfd3ca9a61344c795643aba58ec73a958dc0b315365bc82632e31eced2a2ada684b635e6fead8ef4995ae7b5c4babc46802d137fb
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
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
|
-
|
277
|
+
update_expression_opts = self.class.send(
|
274
278
|
:_build_update_expression,
|
275
279
|
update_pairs
|
276
280
|
)
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
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]
|
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 =
|
595
|
-
raise Errors::KeyMissing, "Missing required key #{attr_sym} in #{
|
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
|
-
|
607
|
-
|
608
|
-
|
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
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
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
|
-
|
289
|
+
update_expression_opts = update_record.class.send(
|
289
290
|
:_build_update_expression,
|
290
291
|
dirty_changes
|
291
292
|
)
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
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.
|
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-
|
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
|