aws-record 2.10.1 → 2.11.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 +5 -0
- data/VERSION +1 -1
- data/lib/aws-record/record/attribute.rb +4 -6
- data/lib/aws-record/record/attributes.rb +36 -49
- data/lib/aws-record/record/batch.rb +13 -12
- data/lib/aws-record/record/batch_read.rb +5 -2
- data/lib/aws-record/record/buildable_search.rb +29 -26
- data/lib/aws-record/record/client_configuration.rb +9 -9
- data/lib/aws-record/record/dirty_tracking.rb +29 -32
- data/lib/aws-record/record/errors.rb +0 -1
- data/lib/aws-record/record/item_collection.rb +4 -4
- data/lib/aws-record/record/item_data.rb +3 -6
- data/lib/aws-record/record/item_operations.rb +77 -93
- data/lib/aws-record/record/key_attributes.rb +0 -2
- data/lib/aws-record/record/marshalers/boolean_marshaler.rb +1 -4
- data/lib/aws-record/record/marshalers/date_marshaler.rb +0 -3
- data/lib/aws-record/record/marshalers/date_time_marshaler.rb +1 -2
- data/lib/aws-record/record/marshalers/epoch_time_marshaler.rb +0 -2
- data/lib/aws-record/record/marshalers/float_marshaler.rb +2 -7
- data/lib/aws-record/record/marshalers/integer_marshaler.rb +2 -7
- data/lib/aws-record/record/marshalers/list_marshaler.rb +1 -4
- data/lib/aws-record/record/marshalers/map_marshaler.rb +1 -4
- data/lib/aws-record/record/marshalers/numeric_set_marshaler.rb +2 -4
- data/lib/aws-record/record/marshalers/string_marshaler.rb +1 -4
- data/lib/aws-record/record/marshalers/string_set_marshaler.rb +2 -4
- data/lib/aws-record/record/marshalers/time_marshaler.rb +0 -2
- data/lib/aws-record/record/model_attributes.rb +13 -23
- data/lib/aws-record/record/query.rb +6 -9
- data/lib/aws-record/record/secondary_indexes.rb +22 -30
- data/lib/aws-record/record/table_config.rb +51 -62
- data/lib/aws-record/record/table_migration.rb +42 -54
- data/lib/aws-record/record/transactions.rb +32 -35
- data/lib/aws-record/record.rb +29 -37
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 737cba9ded94a3d3785cda00b45989e7deee3592c53cae2f4a63a769f1ba3f55
|
4
|
+
data.tar.gz: 1f086b7c3958985bc57ca2a39b22255e88cee84fe0930118ad6c5b8ff78e3c2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cd823dc1edfe588f87d2b7f770a4fa25ca248a055940196264660b803bac3ecce4714f6fb5cb157e1d7d0a668b41bcade92de49851f87f336aaacc6406af167
|
7
|
+
data.tar.gz: 3174f0eb63e34a421b3cbe4c494f7c86ddf5a66e1da6e572351a294cbdfad89b4bd0a41197b7b569b67967e270fe57a9e8f5b07ddedb411d1225e27a0c958b9b
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.11.0
|
@@ -2,14 +2,12 @@
|
|
2
2
|
|
3
3
|
module Aws
|
4
4
|
module Record
|
5
|
-
|
6
5
|
# This class provides helper methods for +Aws::Record+ attributes. These
|
7
6
|
# include marshalers for type casting of item attributes, the Amazon
|
8
7
|
# DynamoDB type for use in certain table and item operation calls, and the
|
9
8
|
# ability to define a database name that is separate from the name used
|
10
9
|
# within the model class and item instances.
|
11
10
|
class Attribute
|
12
|
-
|
13
11
|
attr_reader :name, :database_name, :dynamodb_type
|
14
12
|
|
15
13
|
# @param [Symbol] name Name of the attribute. It should be a name that is
|
@@ -38,7 +36,7 @@ module Aws
|
|
38
36
|
# be used as a default value.
|
39
37
|
def initialize(name, options = {})
|
40
38
|
@name = name
|
41
|
-
@database_name = (options[:database_attribute_name]
|
39
|
+
@database_name = (options[:database_attribute_name] || name).to_s
|
42
40
|
@dynamodb_type = options[:dynamodb_type]
|
43
41
|
@marshaler = options[:marshaler] || DefaultMarshaler
|
44
42
|
@persist_nil = options[:persist_nil]
|
@@ -90,6 +88,7 @@ module Aws
|
|
90
88
|
end
|
91
89
|
|
92
90
|
private
|
91
|
+
|
93
92
|
def _deep_copy(obj)
|
94
93
|
Marshal.load(Marshal.dump(obj))
|
95
94
|
end
|
@@ -97,17 +96,16 @@ module Aws
|
|
97
96
|
def _is_lambda?(obj)
|
98
97
|
obj.respond_to?(:call)
|
99
98
|
end
|
100
|
-
|
101
99
|
end
|
102
100
|
|
103
101
|
# This is an identity marshaler, which performs no changes for type casting
|
104
102
|
# or serialization. It is generally not recommended for use.
|
105
103
|
module DefaultMarshaler
|
106
|
-
def self.type_cast(raw_value,
|
104
|
+
def self.type_cast(raw_value, _options = {})
|
107
105
|
raw_value
|
108
106
|
end
|
109
107
|
|
110
|
-
def self.serialize(raw_value,
|
108
|
+
def self.serialize(raw_value, _options = {})
|
111
109
|
raw_value
|
112
110
|
end
|
113
111
|
end
|
@@ -3,15 +3,12 @@
|
|
3
3
|
module Aws
|
4
4
|
module Record
|
5
5
|
module Attributes
|
6
|
-
|
7
6
|
def self.included(sub_class)
|
8
7
|
sub_class.extend(ClassMethods)
|
9
8
|
model_attributes = ModelAttributes.new(self)
|
10
|
-
sub_class.instance_variable_set(
|
11
|
-
sub_class.instance_variable_set(
|
12
|
-
if Aws::Record.extends_record?(sub_class)
|
13
|
-
inherit_attributes(sub_class)
|
14
|
-
end
|
9
|
+
sub_class.instance_variable_set('@attributes', model_attributes)
|
10
|
+
sub_class.instance_variable_set('@keys', KeyAttributes.new(model_attributes))
|
11
|
+
inherit_attributes(sub_class) if Aws::Record.extends_record?(sub_class)
|
15
12
|
end
|
16
13
|
|
17
14
|
# Base initialization method for a new item. Optionally, allows you to
|
@@ -80,29 +77,24 @@ module Aws
|
|
80
77
|
@data.hash_copy
|
81
78
|
end
|
82
79
|
|
83
|
-
private
|
84
80
|
def self.inherit_attributes(klass)
|
85
|
-
superclass_attributes = klass.superclass.instance_variable_get(
|
81
|
+
superclass_attributes = klass.superclass.instance_variable_get('@attributes')
|
86
82
|
|
87
83
|
superclass_attributes.attributes.each do |name, attribute|
|
88
|
-
subclass_attributes = klass.instance_variable_get(
|
84
|
+
subclass_attributes = klass.instance_variable_get('@attributes')
|
89
85
|
subclass_attributes.register_superclass_attribute(name, attribute)
|
90
86
|
end
|
91
87
|
|
92
|
-
superclass_keys = klass.superclass.instance_variable_get(
|
93
|
-
subclass_keys = klass.instance_variable_get(
|
94
|
-
|
95
|
-
if superclass_keys.hash_key
|
96
|
-
subclass_keys.hash_key = superclass_keys.hash_key
|
97
|
-
end
|
88
|
+
superclass_keys = klass.superclass.instance_variable_get('@keys')
|
89
|
+
subclass_keys = klass.instance_variable_get('@keys')
|
98
90
|
|
99
|
-
if superclass_keys.
|
100
|
-
|
101
|
-
end
|
91
|
+
subclass_keys.hash_key = superclass_keys.hash_key if superclass_keys.hash_key
|
92
|
+
subclass_keys.range_key = superclass_keys.range_key if superclass_keys.range_key
|
102
93
|
end
|
103
94
|
|
104
|
-
|
95
|
+
private_class_method :inherit_attributes
|
105
96
|
|
97
|
+
module ClassMethods
|
106
98
|
# Define an attribute for your model, providing your own attribute type.
|
107
99
|
#
|
108
100
|
# @param [Symbol] name Name of this attribute. It should be a name that
|
@@ -157,7 +149,7 @@ module Aws
|
|
157
149
|
# item is nil or not set at persistence time. Additionally, lambda
|
158
150
|
# can be used as a default value.
|
159
151
|
def string_attr(name, opts = {})
|
160
|
-
opts[:dynamodb_type] =
|
152
|
+
opts[:dynamodb_type] = 'S'
|
161
153
|
attr(name, Marshalers::StringMarshaler.new(opts), opts)
|
162
154
|
end
|
163
155
|
|
@@ -179,7 +171,7 @@ module Aws
|
|
179
171
|
# item is nil or not set at persistence time. Additionally, lambda
|
180
172
|
# can be used as a default value.
|
181
173
|
def boolean_attr(name, opts = {})
|
182
|
-
opts[:dynamodb_type] =
|
174
|
+
opts[:dynamodb_type] = 'BOOL'
|
183
175
|
attr(name, Marshalers::BooleanMarshaler.new(opts), opts)
|
184
176
|
end
|
185
177
|
|
@@ -201,7 +193,7 @@ module Aws
|
|
201
193
|
# item is nil or not set at persistence time. Additionally, lambda
|
202
194
|
# can be used as a default value.
|
203
195
|
def integer_attr(name, opts = {})
|
204
|
-
opts[:dynamodb_type] =
|
196
|
+
opts[:dynamodb_type] = 'N'
|
205
197
|
attr(name, Marshalers::IntegerMarshaler.new(opts), opts)
|
206
198
|
end
|
207
199
|
|
@@ -223,7 +215,7 @@ module Aws
|
|
223
215
|
# item is nil or not set at persistence time. Additionally, lambda
|
224
216
|
# can be used as a default value.
|
225
217
|
def float_attr(name, opts = {})
|
226
|
-
opts[:dynamodb_type] =
|
218
|
+
opts[:dynamodb_type] = 'N'
|
227
219
|
attr(name, Marshalers::FloatMarshaler.new(opts), opts)
|
228
220
|
end
|
229
221
|
|
@@ -245,7 +237,7 @@ module Aws
|
|
245
237
|
# item is nil or not set at persistence time. Additionally, lambda
|
246
238
|
# can be used as a default value.
|
247
239
|
def date_attr(name, opts = {})
|
248
|
-
opts[:dynamodb_type] =
|
240
|
+
opts[:dynamodb_type] = 'S'
|
249
241
|
attr(name, Marshalers::DateMarshaler.new(opts), opts)
|
250
242
|
end
|
251
243
|
|
@@ -267,7 +259,7 @@ module Aws
|
|
267
259
|
# item is nil or not set at persistence time. Additionally, lambda
|
268
260
|
# can be used as a default value.
|
269
261
|
def datetime_attr(name, opts = {})
|
270
|
-
opts[:dynamodb_type] =
|
262
|
+
opts[:dynamodb_type] = 'S'
|
271
263
|
attr(name, Marshalers::DateTimeMarshaler.new(opts), opts)
|
272
264
|
end
|
273
265
|
|
@@ -289,7 +281,7 @@ module Aws
|
|
289
281
|
# item is nil or not set at persistence time. Additionally, lambda
|
290
282
|
# can be used as a default value.
|
291
283
|
def time_attr(name, opts = {})
|
292
|
-
opts[:dynamodb_type] =
|
284
|
+
opts[:dynamodb_type] = 'S'
|
293
285
|
attr(name, Marshalers::TimeMarshaler.new(opts), opts)
|
294
286
|
end
|
295
287
|
|
@@ -312,7 +304,7 @@ module Aws
|
|
312
304
|
# item is nil or not set at persistence time. Additionally, lambda
|
313
305
|
# can be used as a default value.
|
314
306
|
def epoch_time_attr(name, opts = {})
|
315
|
-
opts[:dynamodb_type] =
|
307
|
+
opts[:dynamodb_type] = 'N'
|
316
308
|
attr(name, Marshalers::EpochTimeMarshaler.new(opts), opts)
|
317
309
|
end
|
318
310
|
|
@@ -348,7 +340,7 @@ module Aws
|
|
348
340
|
# item is nil or not set at persistence time. Additionally, lambda
|
349
341
|
# can be used as a default value.
|
350
342
|
def list_attr(name, opts = {})
|
351
|
-
opts[:dynamodb_type] =
|
343
|
+
opts[:dynamodb_type] = 'L'
|
352
344
|
attr(name, Marshalers::ListMarshaler.new(opts), opts)
|
353
345
|
end
|
354
346
|
|
@@ -384,7 +376,7 @@ module Aws
|
|
384
376
|
# item is nil or not set at persistence time. Additionally, lambda
|
385
377
|
# can be used as a default value.
|
386
378
|
def map_attr(name, opts = {})
|
387
|
-
opts[:dynamodb_type] =
|
379
|
+
opts[:dynamodb_type] = 'M'
|
388
380
|
attr(name, Marshalers::MapMarshaler.new(opts), opts)
|
389
381
|
end
|
390
382
|
|
@@ -410,7 +402,7 @@ module Aws
|
|
410
402
|
# item is nil or not set at persistence time. Additionally, lambda
|
411
403
|
# can be used as a default value.
|
412
404
|
def string_set_attr(name, opts = {})
|
413
|
-
opts[:dynamodb_type] =
|
405
|
+
opts[:dynamodb_type] = 'SS'
|
414
406
|
attr(name, Marshalers::StringSetMarshaler.new(opts), opts)
|
415
407
|
end
|
416
408
|
|
@@ -436,7 +428,7 @@ module Aws
|
|
436
428
|
# item is nil or not set at persistence time. Additionally, lambda
|
437
429
|
# can be used as a default value.
|
438
430
|
def numeric_set_attr(name, opts = {})
|
439
|
-
opts[:dynamodb_type] =
|
431
|
+
opts[:dynamodb_type] = 'NS'
|
440
432
|
attr(name, Marshalers::NumericSetMarshaler.new(opts), opts)
|
441
433
|
end
|
442
434
|
|
@@ -452,8 +444,8 @@ module Aws
|
|
452
444
|
# * None of the attributes have dirty changes.
|
453
445
|
# * If there is a value passed in, it must be an integer.
|
454
446
|
# For more information, see
|
455
|
-
# {https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html#WorkingWithItems.AtomicCounters
|
456
|
-
# in the Amazon DynamoDB Developer Guide.
|
447
|
+
# {https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html#WorkingWithItems.AtomicCounters
|
448
|
+
# Atomic counter} in the Amazon DynamoDB Developer Guide.
|
457
449
|
#
|
458
450
|
# @param [Symbol] name Name of this attribute. It should be a name that
|
459
451
|
# is safe to use as a method.
|
@@ -476,14 +468,13 @@ module Aws
|
|
476
468
|
# record.increment_counter!(2) #=> 3
|
477
469
|
# @see #attr #attr method for additional hash options.
|
478
470
|
def atomic_counter(name, opts = {})
|
479
|
-
opts[:dynamodb_type] =
|
471
|
+
opts[:dynamodb_type] = 'N'
|
480
472
|
opts[:default_value] ||= 0
|
481
473
|
attr(name, Marshalers::IntegerMarshaler.new(opts), opts)
|
482
474
|
|
483
|
-
define_method("increment_#{name}!") do |increment=1|
|
484
|
-
|
475
|
+
define_method("increment_#{name}!") do |increment = 1|
|
485
476
|
if dirty?
|
486
|
-
msg =
|
477
|
+
msg = 'Attributes need to be saved before atomic counter can be incremented'
|
487
478
|
raise Errors::RecordError, msg
|
488
479
|
end
|
489
480
|
|
@@ -492,23 +483,22 @@ module Aws
|
|
492
483
|
raise ArgumentError, msg
|
493
484
|
end
|
494
485
|
|
495
|
-
resp = dynamodb_client.update_item(
|
486
|
+
resp = dynamodb_client.update_item(
|
496
487
|
table_name: self.class.table_name,
|
497
488
|
key: key_values,
|
498
489
|
expression_attribute_values: {
|
499
|
-
|
490
|
+
':i' => increment
|
500
491
|
},
|
501
492
|
expression_attribute_names: {
|
502
|
-
|
493
|
+
'#n' => name
|
503
494
|
},
|
504
|
-
update_expression:
|
505
|
-
return_values:
|
506
|
-
|
495
|
+
update_expression: 'SET #n = #n + :i',
|
496
|
+
return_values: 'UPDATED_NEW'
|
497
|
+
)
|
507
498
|
assign_attributes(resp[:attributes])
|
508
499
|
@data.clean!
|
509
500
|
@data.get_attribute(name)
|
510
501
|
end
|
511
|
-
|
512
502
|
end
|
513
503
|
|
514
504
|
# @return [Symbol,nil] The symbolic name of the table's hash key.
|
@@ -532,6 +522,7 @@ module Aws
|
|
532
522
|
end
|
533
523
|
|
534
524
|
private
|
525
|
+
|
535
526
|
def _define_attr_methods(name)
|
536
527
|
define_method(name) do
|
537
528
|
@data.get_attribute(name)
|
@@ -544,18 +535,14 @@ module Aws
|
|
544
535
|
|
545
536
|
def _key_attributes(id, opts)
|
546
537
|
if opts[:hash_key] == true && opts[:range_key] == true
|
547
|
-
raise ArgumentError.
|
548
|
-
"Cannot have the same attribute be a hash and range key."
|
549
|
-
)
|
538
|
+
raise ArgumentError, 'Cannot have the same attribute be a hash and range key.'
|
550
539
|
elsif opts[:hash_key] == true
|
551
540
|
@keys.hash_key = id
|
552
541
|
elsif opts[:range_key] == true
|
553
542
|
@keys.range_key = id
|
554
543
|
end
|
555
544
|
end
|
556
|
-
|
557
545
|
end
|
558
|
-
|
559
546
|
end
|
560
547
|
end
|
561
548
|
end
|
@@ -7,10 +7,10 @@ module Aws
|
|
7
7
|
|
8
8
|
class << self
|
9
9
|
# Provides a thin wrapper to the
|
10
|
-
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#batch_write_item-instance_method
|
11
|
-
# method. Up to 25 +PutItem+ or +DeleteItem+
|
12
|
-
# A single request may write up to 16 MB of data, with each
|
13
|
-
# write limit of 400 KB.
|
10
|
+
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#batch_write_item-instance_method
|
11
|
+
# Aws::DynamoDB::Client#batch_write_item} method. Up to 25 +PutItem+ or +DeleteItem+
|
12
|
+
# operations are supported. A single request may write up to 16 MB of data, with each
|
13
|
+
# item having a write limit of 400 KB.
|
14
14
|
#
|
15
15
|
# *Note*: this operation does not support dirty attribute handling,
|
16
16
|
# nor does it enforce safe write operations (i.e. update vs new record
|
@@ -25,8 +25,9 @@ module Aws
|
|
25
25
|
# when all operations have been completed.
|
26
26
|
#
|
27
27
|
# Please see
|
28
|
-
# {https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.Errors.html#Programming.Errors.BatchOperations
|
29
|
-
# in the DynamoDB Developer Guide for
|
28
|
+
# {https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.Errors.html#Programming.Errors.BatchOperations
|
29
|
+
# Batch Operations and Error Handling} in the DynamoDB Developer Guide for
|
30
|
+
# more details.
|
30
31
|
#
|
31
32
|
# @example Usage Example
|
32
33
|
# class Breakfast
|
@@ -54,15 +55,16 @@ module Aws
|
|
54
55
|
# @param [Hash] opts the options you wish to use to create the client.
|
55
56
|
# Note that if you include the option +:client+, all other options
|
56
57
|
# will be ignored. See the documentation for other options in the
|
57
|
-
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#initialize-instance_method
|
58
|
+
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#initialize-instance_method
|
59
|
+
# AWS SDK for Ruby}.
|
58
60
|
# @option opts [Aws::DynamoDB::Client] :client allows you to pass in your
|
59
61
|
# own pre-configured client.
|
60
62
|
#
|
61
63
|
# @return [Aws::Record::BatchWrite] An instance that contains any
|
62
64
|
# unprocessed items and allows for a retry strategy.
|
63
|
-
def write(opts = {}
|
65
|
+
def write(opts = {})
|
64
66
|
batch = BatchWrite.new(client: _build_client(opts))
|
65
|
-
|
67
|
+
yield(batch)
|
66
68
|
batch.execute!
|
67
69
|
end
|
68
70
|
|
@@ -133,13 +135,12 @@ module Aws
|
|
133
135
|
# @return [Aws::Record::BatchRead] An instance that contains modeled items
|
134
136
|
# from the +BatchGetItem+ result and stores unprocessed keys to be
|
135
137
|
# manually processed later.
|
136
|
-
def read(opts = {}
|
138
|
+
def read(opts = {})
|
137
139
|
batch = BatchRead.new(client: _build_client(opts))
|
138
|
-
|
140
|
+
yield(batch)
|
139
141
|
batch.execute!
|
140
142
|
batch
|
141
143
|
end
|
142
|
-
|
143
144
|
end
|
144
145
|
end
|
145
146
|
end
|
@@ -64,7 +64,10 @@ module Aws
|
|
64
64
|
def each
|
65
65
|
return enum_for(:each) unless block_given?
|
66
66
|
|
67
|
-
@items.each
|
67
|
+
@items.each do |item|
|
68
|
+
yield(item)
|
69
|
+
end
|
70
|
+
|
68
71
|
until complete?
|
69
72
|
new_items = execute!
|
70
73
|
new_items.each { |new_item| yield new_item }
|
@@ -156,7 +159,7 @@ module Aws
|
|
156
159
|
|
157
160
|
def update_unprocessed_keys(keys)
|
158
161
|
keys.each do |table_name, table_values|
|
159
|
-
table_values.keys.each do |key|
|
162
|
+
table_values.keys.each do |key| # rubocop:disable Style/HashEachMethods
|
160
163
|
unprocessed_keys << { keys: key, table_name: table_name }
|
161
164
|
end
|
162
165
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Aws
|
4
4
|
module Record
|
5
5
|
class BuildableSearch
|
6
|
-
SUPPORTED_OPERATIONS = [
|
6
|
+
SUPPORTED_OPERATIONS = %i[query scan].freeze
|
7
7
|
|
8
8
|
# This should never be called directly, rather it is called by the
|
9
9
|
# #build_query or #build_scan methods of your aws-record model class.
|
@@ -13,12 +13,12 @@ module Aws
|
|
13
13
|
if SUPPORTED_OPERATIONS.include?(operation)
|
14
14
|
@operation = operation
|
15
15
|
else
|
16
|
-
raise ArgumentError
|
16
|
+
raise ArgumentError, "Unsupported operation: #{operation}"
|
17
17
|
end
|
18
18
|
@model = model
|
19
19
|
@params = {}
|
20
|
-
@next_name =
|
21
|
-
@next_value =
|
20
|
+
@next_name = 'BUILDERA'
|
21
|
+
@next_value = 'buildera'
|
22
22
|
end
|
23
23
|
|
24
24
|
# If you are querying or scanning on an index, you can specify it with
|
@@ -42,10 +42,10 @@ module Aws
|
|
42
42
|
# the :segment number of this scan.
|
43
43
|
def parallel_scan(opts)
|
44
44
|
unless @operation == :scan
|
45
|
-
raise ArgumentError
|
45
|
+
raise ArgumentError, 'parallel_scan is only supported for scans'
|
46
46
|
end
|
47
47
|
unless opts[:total_segments] && opts[:segment]
|
48
|
-
raise ArgumentError
|
48
|
+
raise ArgumentError, 'Must specify :total_segments and :segment in a parallel scan.'
|
49
49
|
end
|
50
50
|
@params[:total_segments] = opts[:total_segments]
|
51
51
|
@params[:segment] = opts[:segment]
|
@@ -57,7 +57,7 @@ module Aws
|
|
57
57
|
# run in ascending order.
|
58
58
|
def scan_ascending(b)
|
59
59
|
unless @operation == :query
|
60
|
-
raise ArgumentError
|
60
|
+
raise ArgumentError, 'scan_ascending is only supported for queries.'
|
61
61
|
end
|
62
62
|
@params[:scan_index_forward] = b
|
63
63
|
self
|
@@ -91,7 +91,7 @@ module Aws
|
|
91
91
|
# q.to_a # You can use this like any other query result in aws-record
|
92
92
|
def key_expr(statement_str, *subs)
|
93
93
|
unless @operation == :query
|
94
|
-
raise ArgumentError
|
94
|
+
raise ArgumentError, 'key_expr is only supported for queries.'
|
95
95
|
end
|
96
96
|
names = @params[:expression_attribute_names]
|
97
97
|
if names.nil?
|
@@ -145,10 +145,10 @@ module Aws
|
|
145
145
|
|
146
146
|
# Allows you to define a projection expression for the values returned by
|
147
147
|
# a query or scan. See
|
148
|
-
# {https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ProjectionExpressions.html
|
149
|
-
# for more details on projection expressions.
|
150
|
-
# your aws-record model class in a projection expression.
|
151
|
-
# retrieved.
|
148
|
+
# {https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ProjectionExpressions.html
|
149
|
+
# the Amazon DynamoDB Developer Guide} for more details on projection expressions.
|
150
|
+
# You can use the symbols from your aws-record model class in a projection expression.
|
151
|
+
# Keys are always retrieved.
|
152
152
|
#
|
153
153
|
# @example Scan with a projection expression:
|
154
154
|
# # Example model class
|
@@ -233,30 +233,33 @@ module Aws
|
|
233
233
|
end
|
234
234
|
|
235
235
|
private
|
236
|
+
|
236
237
|
def _key_pass(statement, names)
|
237
238
|
statement.gsub(/:(\w+)/) do |match|
|
238
|
-
key = match.gsub(':','').to_sym
|
239
|
+
key = match.gsub(':', '').to_sym
|
239
240
|
key_name = @model.attributes.storage_name_for(key)
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
241
|
+
|
242
|
+
raise "No such key #{key}" unless key_name
|
243
|
+
|
244
|
+
sub_name = _next_name
|
245
|
+
|
246
|
+
raise 'Substitution collision!' if names[sub_name]
|
247
|
+
|
248
|
+
names[sub_name] = key_name
|
249
|
+
sub_name
|
248
250
|
end
|
249
251
|
end
|
250
252
|
|
251
253
|
def _apply_values(statement, subs, values)
|
252
254
|
count = 0
|
253
|
-
statement.gsub(/[?]/) do
|
255
|
+
result = statement.gsub(/[?]/) do ||
|
254
256
|
sub_value = _next_value
|
255
|
-
raise
|
257
|
+
raise 'Substitution collision!' if values[sub_value]
|
256
258
|
values[sub_value] = subs[count]
|
257
259
|
count += 1
|
258
260
|
sub_value
|
259
|
-
end
|
261
|
+
end
|
262
|
+
result.tap do
|
260
263
|
unless count == subs.size
|
261
264
|
raise "Expected #{count} values in the substitution set, but found #{subs.size}"
|
262
265
|
end
|
@@ -264,13 +267,13 @@ module Aws
|
|
264
267
|
end
|
265
268
|
|
266
269
|
def _next_name
|
267
|
-
ret =
|
270
|
+
ret = '#' + @next_name
|
268
271
|
@next_name = @next_name.next
|
269
272
|
ret
|
270
273
|
end
|
271
274
|
|
272
275
|
def _next_value
|
273
|
-
ret =
|
276
|
+
ret = ':' + @next_value
|
274
277
|
@next_value = @next_value.next
|
275
278
|
ret
|
276
279
|
end
|
@@ -20,16 +20,19 @@ module Aws
|
|
20
20
|
# @param [Hash] opts the options you wish to use to create the client.
|
21
21
|
# Note that if you include the option +:client+, all other options
|
22
22
|
# will be ignored. See the documentation for other options in the
|
23
|
-
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#initialize-instance_method
|
23
|
+
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#initialize-instance_method
|
24
|
+
# AWS SDK for Ruby}.
|
24
25
|
# @option opts [Aws::DynamoDB::Client] :client allows you to pass in your
|
25
26
|
# own pre-configured client.
|
26
27
|
def configure_client(opts = {})
|
28
|
+
# rubocop:disable Style/RedundantSelf
|
27
29
|
if self.class != Module && Aws::Record.extends_record?(self) && opts.empty? &&
|
28
|
-
|
29
|
-
|
30
|
+
self.superclass.instance_variable_get('@dynamodb_client')
|
31
|
+
@dynamodb_client = self.superclass.instance_variable_get('@dynamodb_client')
|
30
32
|
else
|
31
33
|
@dynamodb_client = _build_client(opts)
|
32
34
|
end
|
35
|
+
# rubocop:enable Style/RedundantSelf
|
33
36
|
end
|
34
37
|
|
35
38
|
# Gets the
|
@@ -50,12 +53,9 @@ module Aws
|
|
50
53
|
|
51
54
|
def _build_client(opts = {})
|
52
55
|
provided_client = opts.delete(:client)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
def _user_agent(custom)
|
58
|
-
custom || " aws-record/#{VERSION}"
|
56
|
+
client = provided_client || Aws::DynamoDB::Client.new(opts)
|
57
|
+
client.config.user_agent_frameworks << 'aws-record'
|
58
|
+
client
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|