aws-record 2.7.0 → 2.10.1
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 +330 -0
- data/LICENSE +202 -0
- data/VERSION +1 -0
- data/lib/aws-record/record/attribute.rb +5 -15
- data/lib/aws-record/record/attributes.rb +161 -32
- data/lib/aws-record/record/batch.rb +99 -35
- data/lib/aws-record/record/batch_read.rb +186 -0
- data/lib/aws-record/record/batch_write.rb +9 -14
- data/lib/aws-record/record/buildable_search.rb +4 -2
- data/lib/aws-record/record/client_configuration.rb +13 -14
- data/lib/aws-record/record/dirty_tracking.rb +1 -12
- data/lib/aws-record/record/errors.rb +1 -12
- data/lib/aws-record/record/item_collection.rb +2 -13
- data/lib/aws-record/record/item_data.rb +1 -12
- data/lib/aws-record/record/item_operations.rb +47 -12
- data/lib/aws-record/record/key_attributes.rb +1 -12
- data/lib/aws-record/record/marshalers/boolean_marshaler.rb +1 -12
- data/lib/aws-record/record/marshalers/date_marshaler.rb +1 -12
- data/lib/aws-record/record/marshalers/date_time_marshaler.rb +1 -12
- data/lib/aws-record/record/marshalers/epoch_time_marshaler.rb +1 -12
- data/lib/aws-record/record/marshalers/float_marshaler.rb +1 -12
- data/lib/aws-record/record/marshalers/integer_marshaler.rb +1 -12
- data/lib/aws-record/record/marshalers/list_marshaler.rb +1 -12
- data/lib/aws-record/record/marshalers/map_marshaler.rb +1 -12
- data/lib/aws-record/record/marshalers/numeric_set_marshaler.rb +1 -12
- data/lib/aws-record/record/marshalers/string_marshaler.rb +1 -12
- data/lib/aws-record/record/marshalers/string_set_marshaler.rb +1 -12
- data/lib/aws-record/record/marshalers/time_marshaler.rb +1 -12
- data/lib/aws-record/record/model_attributes.rb +8 -12
- data/lib/aws-record/record/query.rb +1 -12
- data/lib/aws-record/record/secondary_indexes.rb +24 -12
- data/lib/aws-record/record/table_config.rb +1 -12
- data/lib/aws-record/record/table_migration.rb +1 -12
- data/lib/aws-record/record/transactions.rb +39 -7
- data/lib/aws-record/record/version.rb +2 -13
- data/lib/aws-record/record.rb +100 -20
- data/lib/aws-record.rb +2 -12
- metadata +8 -4
@@ -1,15 +1,4 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License"). You may not
|
4
|
-
# use this file except in compliance with the License. A copy of the License is
|
5
|
-
# located at
|
6
|
-
#
|
7
|
-
# http://aws.amazon.com/apache2.0/
|
8
|
-
#
|
9
|
-
# or in the "license" file accompanying this file. This file is distributed on
|
10
|
-
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
11
|
-
# or implied. See the License for the specific language governing permissions
|
12
|
-
# and limitations under the License.
|
1
|
+
# frozen_string_literal: true
|
13
2
|
|
14
3
|
module Aws
|
15
4
|
module Record
|
@@ -1,15 +1,4 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License"). You may not
|
4
|
-
# use this file except in compliance with the License. A copy of the License is
|
5
|
-
# located at
|
6
|
-
#
|
7
|
-
# http://aws.amazon.com/apache2.0/
|
8
|
-
#
|
9
|
-
# or in the "license" file accompanying this file. This file is distributed on
|
10
|
-
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
11
|
-
# or implied. See the License for the specific language governing permissions
|
12
|
-
# and limitations under the License.
|
1
|
+
# frozen_string_literal: true
|
13
2
|
|
14
3
|
module Aws
|
15
4
|
module Record
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Aws
|
2
4
|
module Record
|
3
5
|
module Transactions
|
@@ -26,15 +28,26 @@ module Aws
|
|
26
28
|
# ) # => results.responses contains nil or marshalled items
|
27
29
|
# results.responses.map { |r| r.class } # [TableOne, TableTwo, TableTwo]
|
28
30
|
#
|
29
|
-
# Provides
|
31
|
+
# Provides support for the
|
32
|
+
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#transact_get_items-instance_method
|
33
|
+
# Aws::DynamoDB::Client#transact_get_item} for aws-record models.
|
34
|
+
#
|
35
|
+
# This method runs a transactional find across multiple DynamoDB
|
30
36
|
# items, including transactions which get items across multiple actual
|
31
|
-
# or virtual tables.
|
37
|
+
# or virtual tables. This call can contain up to 100 item keys.
|
38
|
+
#
|
39
|
+
# DynamoDB will reject the request if any of the following is true:
|
40
|
+
# * A conflicting operation is in the process of updating an item to be read.
|
41
|
+
# * There is insufficient provisioned capacity for the transaction to be completed.
|
42
|
+
# * There is a user error, such as an invalid data format.
|
43
|
+
# * The aggregate size of the items in the transaction cannot exceed 4 MB.
|
32
44
|
#
|
33
45
|
# @param [Hash] opts Options to pass through to
|
34
46
|
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#transact_get_items-instance_method Aws::DynamoDB::Client#transact_get_items},
|
35
|
-
# with the exception of the
|
36
|
-
#
|
37
|
-
# metadata used to marshal your items
|
47
|
+
# with the exception of the +:transact_items+ array, which uses the
|
48
|
+
# {ItemOperations.ItemOperationsClassMethods.tfind_opts #tfind_opts} operation
|
49
|
+
# on your model class to provide extra metadata used to marshal your items
|
50
|
+
# after retrieval.
|
38
51
|
# @option opts [Array] :transact_items A set of +#tfind_opts+ results,
|
39
52
|
# such as those created by the usage example.
|
40
53
|
# @option opts [Aws::DynamoDB::Client] :client Optionally, you can pass
|
@@ -137,7 +150,11 @@ module Aws
|
|
137
150
|
# ]
|
138
151
|
# )
|
139
152
|
#
|
140
|
-
# Provides
|
153
|
+
# Provides support for the
|
154
|
+
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#transact_write_items-instance_method
|
155
|
+
# Aws::DynamoDB::Client#transact_write_items} for aws-record models.
|
156
|
+
#
|
157
|
+
# This method passes in aws-record items into transactional writes,
|
141
158
|
# as well as adding the ability to run 'save' commands in a transaction
|
142
159
|
# while allowing aws-record to determine if a :put or :update operation
|
143
160
|
# is most appropriate. +#transact_write+ supports 5 different transact
|
@@ -145,7 +162,7 @@ module Aws
|
|
145
162
|
# - save: Behaves much like the +#save+ operation on the item itself.
|
146
163
|
# If the keys are dirty, and thus it appears to be a new item, will
|
147
164
|
# create a :put operation with a conditional check on the item's
|
148
|
-
#
|
165
|
+
# existence. Note that you cannot bring your own conditional
|
149
166
|
# expression in this case. If you wish to force put or add your
|
150
167
|
# own conditional checks, use the :put operation.
|
151
168
|
# - put: Does a force put for the given item key and model.
|
@@ -153,6 +170,21 @@ module Aws
|
|
153
170
|
# - delete: Deletes the given item.
|
154
171
|
# - check: Takes the result of +#transact_check_expression+,
|
155
172
|
# performing the specified check as a part of the transaction.
|
173
|
+
# See {ItemOperations.ItemOperationsClassMethods.transact_check_expression #transact_check_expression}
|
174
|
+
# for more information.
|
175
|
+
#
|
176
|
+
# This call contain up to 100 action requests.
|
177
|
+
#
|
178
|
+
# DynamoDB will reject the request if any of the following is true:
|
179
|
+
# * A condition in one of the condition expressions is not met.
|
180
|
+
# * An ongoing operation is in the process of updating the same item.
|
181
|
+
# * There is insufficient provisioned capacity for the transaction to
|
182
|
+
# be completed.
|
183
|
+
# * An item size becomes too large (bigger than 400 KB), a local secondary
|
184
|
+
# index (LSI) becomes too large, or a similar validation error occurs
|
185
|
+
# because of changes made by the transaction.
|
186
|
+
# * The aggregate size of the items in the transaction exceeds 4 MB.
|
187
|
+
# * There is a user error, such as an invalid data format.
|
156
188
|
#
|
157
189
|
# @param [Hash] opts Options to pass through to
|
158
190
|
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#transact_write_items-instance_method Aws::DynamoDB::Client#transact_write_items}
|
@@ -1,18 +1,7 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License"). You may not
|
4
|
-
# use this file except in compliance with the License. A copy of the License is
|
5
|
-
# located at
|
6
|
-
#
|
7
|
-
# http://aws.amazon.com/apache2.0/
|
8
|
-
#
|
9
|
-
# or in the "license" file accompanying this file. This file is distributed on
|
10
|
-
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
11
|
-
# or implied. See the License for the specific language governing permissions
|
12
|
-
# and limitations under the License.
|
1
|
+
# frozen_string_literal: true
|
13
2
|
|
14
3
|
module Aws
|
15
4
|
module Record
|
16
|
-
VERSION =
|
5
|
+
VERSION = File.read(File.expand_path('../../../../VERSION', __FILE__)).strip
|
17
6
|
end
|
18
7
|
end
|
data/lib/aws-record/record.rb
CHANGED
@@ -1,15 +1,4 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License"). You may not
|
4
|
-
# use this file except in compliance with the License. A copy of the License is
|
5
|
-
# located at
|
6
|
-
#
|
7
|
-
# http://aws.amazon.com/apache2.0/
|
8
|
-
#
|
9
|
-
# or in the "license" file accompanying this file. This file is distributed on
|
10
|
-
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
11
|
-
# or implied. See the License for the specific language governing permissions
|
12
|
-
# and limitations under the License.
|
1
|
+
# frozen_string_literal: true
|
13
2
|
|
14
3
|
module Aws
|
15
4
|
|
@@ -17,7 +6,19 @@ module Aws
|
|
17
6
|
# decorate them with the Amazon DynamoDB integration methods provided by this
|
18
7
|
# library. Methods you can use are shown below, in sub-modules organized by
|
19
8
|
# functionality.
|
20
|
-
#
|
9
|
+
# === Inheritance Support
|
10
|
+
# Aws Record models can be extended using standard ruby inheritance. The child
|
11
|
+
# model must include +Aws::Record+ in their model and the following will
|
12
|
+
# be inherited:
|
13
|
+
# * {#set_table_name set_table_name}
|
14
|
+
# * {#initialize Attributes and keys}
|
15
|
+
# * Mutation Tracking:
|
16
|
+
# * {#enable_mutation_tracking enable_mutation_tracking}
|
17
|
+
# * {#disable_mutation_tracking disable_mutation_tracking}
|
18
|
+
# * {#local_secondary_indexes local_secondary_indexes}
|
19
|
+
# * {#global_secondary_indexes global_secondary_indexes}
|
20
|
+
# * {ClientConfiguration#configure_client configure_client}
|
21
|
+
# See example below to see the feature in action.
|
21
22
|
# @example A class definition using +Aws::Record+
|
22
23
|
# class MyModel
|
23
24
|
# include Aws::Record
|
@@ -28,6 +29,21 @@ module Aws
|
|
28
29
|
# string_set_attr :tags
|
29
30
|
# map_attr :metadata
|
30
31
|
# end
|
32
|
+
# @example Inheritance between models
|
33
|
+
# class Animal
|
34
|
+
# include Aws::Record
|
35
|
+
# string_attr :name, hash_key: true
|
36
|
+
# integer_attr :age
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# class Dog < Animal
|
40
|
+
# include Aws::Record
|
41
|
+
# boolean_attr :family_friendly
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# dog = Dog.find(name: 'Sunflower')
|
45
|
+
# dog.age = 3
|
46
|
+
# dog.family_friendly = true
|
31
47
|
module Record
|
32
48
|
# @!parse extend RecordClassMethods
|
33
49
|
# @!parse include Attributes
|
@@ -57,6 +73,14 @@ module Aws
|
|
57
73
|
sub_class.send(:include, DirtyTracking)
|
58
74
|
sub_class.send(:include, Query)
|
59
75
|
sub_class.send(:include, SecondaryIndexes)
|
76
|
+
if Aws::Record.extends_record?(sub_class)
|
77
|
+
inherit_track_mutations(sub_class)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# @api private
|
82
|
+
def self.extends_record?(klass)
|
83
|
+
klass.superclass.include?(Aws::Record)
|
60
84
|
end
|
61
85
|
|
62
86
|
private
|
@@ -64,6 +88,11 @@ module Aws
|
|
64
88
|
self.class.dynamodb_client
|
65
89
|
end
|
66
90
|
|
91
|
+
def self.inherit_track_mutations(klass)
|
92
|
+
superclass_track_mutations = klass.superclass.instance_variable_get("@track_mutations")
|
93
|
+
klass.instance_variable_set("@track_mutations", superclass_track_mutations)
|
94
|
+
end
|
95
|
+
|
67
96
|
module RecordClassMethods
|
68
97
|
|
69
98
|
# Returns the Amazon DynamoDB table name for this model class.
|
@@ -72,12 +101,14 @@ module Aws
|
|
72
101
|
# also define a custom table name at the class level to be anything that
|
73
102
|
# you want.
|
74
103
|
#
|
104
|
+
# *Note*: +table_name+ is inherited from a parent model when {set_table_name}
|
105
|
+
# is explicitly specified in the parent.
|
75
106
|
# @example
|
76
107
|
# class MyTable
|
77
108
|
# include Aws::Record
|
78
109
|
# end
|
79
110
|
#
|
80
|
-
# class
|
111
|
+
# class MyOtherTable
|
81
112
|
# include Aws::Record
|
82
113
|
# set_table_name "test_MyTable"
|
83
114
|
# end
|
@@ -85,29 +116,65 @@ module Aws
|
|
85
116
|
# MyTable.table_name # => "MyTable"
|
86
117
|
# MyOtherTable.table_name # => "test_MyTable"
|
87
118
|
def table_name
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
119
|
+
@table_name ||= begin
|
120
|
+
if Aws::Record.extends_record?(self) &&
|
121
|
+
default_table_name(self.superclass) != self.superclass.table_name
|
122
|
+
self.superclass.instance_variable_get('@table_name')
|
123
|
+
else
|
124
|
+
default_table_name(self)
|
125
|
+
end
|
92
126
|
end
|
93
127
|
end
|
94
128
|
|
95
129
|
# Allows you to set a custom Amazon DynamoDB table name for this model
|
96
130
|
# class.
|
131
|
+
# === Inheritance Support
|
132
|
+
# +table_name+ is inherited from a parent model when it is explicitly specified
|
133
|
+
# in the parent.
|
97
134
|
#
|
98
|
-
#
|
135
|
+
# The parent model will need to have +set_table_name+ defined in their model
|
136
|
+
# for the child model to inherit the +table_name+.
|
137
|
+
# If no +set_table_name+ is defined, the parent and child models will have separate
|
138
|
+
# table names based on their class name.
|
139
|
+
#
|
140
|
+
# If both parent and child models have defined +set_table_name+ in their model,
|
141
|
+
# the child model will override the +table_name+ with theirs.
|
142
|
+
# @example Setting custom table name for model class
|
99
143
|
# class MyTable
|
100
144
|
# include Aws::Record
|
101
145
|
# set_table_name "prod_MyTable"
|
102
146
|
# end
|
103
147
|
#
|
104
|
-
# class
|
148
|
+
# class MyOtherTable
|
105
149
|
# include Aws::Record
|
106
150
|
# set_table_name "test_MyTable"
|
107
151
|
# end
|
108
152
|
#
|
109
153
|
# MyTable.table_name # => "prod_MyTable"
|
110
154
|
# MyOtherTable.table_name # => "test_MyTable"
|
155
|
+
# @example Child model inherits table name from Parent model
|
156
|
+
# class Animal
|
157
|
+
# include Aws::Record
|
158
|
+
# set_table_name "AnimalTable"
|
159
|
+
# end
|
160
|
+
#
|
161
|
+
# class Dog < Animal
|
162
|
+
# include Aws::Record
|
163
|
+
# end
|
164
|
+
#
|
165
|
+
# Dog.table_name # => "AnimalTable"
|
166
|
+
# @example Child model overrides table name from Parent model
|
167
|
+
# class Animal
|
168
|
+
# include Aws::Record
|
169
|
+
# set_table_name "AnimalTable"
|
170
|
+
# end
|
171
|
+
#
|
172
|
+
# class Dog < Animal
|
173
|
+
# include Aws::Record
|
174
|
+
# set_table_name "DogTable"
|
175
|
+
# end
|
176
|
+
#
|
177
|
+
# Dog.table_name # => "DogTable"
|
111
178
|
def set_table_name(name)
|
112
179
|
@table_name = name
|
113
180
|
end
|
@@ -149,6 +216,9 @@ module Aws
|
|
149
216
|
end
|
150
217
|
|
151
218
|
# Turns off mutation tracking for all attributes in the model.
|
219
|
+
#
|
220
|
+
# *Note*: +disable_mutation_tracking+ is inherited from a parent model
|
221
|
+
# when it is explicitly specified in the parent.
|
152
222
|
def disable_mutation_tracking
|
153
223
|
@track_mutations = false
|
154
224
|
end
|
@@ -158,6 +228,9 @@ module Aws
|
|
158
228
|
# call this. It is provided in case there is a need to dynamically turn
|
159
229
|
# this feature on and off, though that would be generally discouraged and
|
160
230
|
# could cause inaccurate mutation tracking at runtime.
|
231
|
+
#
|
232
|
+
# *Note*: +enable_mutation_tracking+ is inherited from a parent model
|
233
|
+
# when it is explicitly specified in the parent.
|
161
234
|
def enable_mutation_tracking
|
162
235
|
@track_mutations = true
|
163
236
|
end
|
@@ -177,6 +250,13 @@ module Aws
|
|
177
250
|
raise Errors::InvalidModel.new("Table models must include a hash key")
|
178
251
|
end
|
179
252
|
end
|
253
|
+
|
254
|
+
private
|
255
|
+
def default_table_name(klass)
|
256
|
+
return unless klass.name
|
257
|
+
klass.name.split("::").join("_")
|
258
|
+
end
|
259
|
+
|
180
260
|
end
|
181
261
|
end
|
182
262
|
end
|
data/lib/aws-record.rb
CHANGED
@@ -1,15 +1,4 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License"). You may not
|
4
|
-
# use this file except in compliance with the License. A copy of the License is
|
5
|
-
# located at
|
6
|
-
#
|
7
|
-
# http://aws.amazon.com/apache2.0/
|
8
|
-
#
|
9
|
-
# or in the "license" file accompanying this file. This file is distributed on
|
10
|
-
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
11
|
-
# or implied. See the License for the specific language governing permissions
|
12
|
-
# and limitations under the License.
|
1
|
+
# frozen_string_literal: true
|
13
2
|
|
14
3
|
require 'aws-sdk-dynamodb'
|
15
4
|
require_relative 'aws-record/record/client_configuration'
|
@@ -30,6 +19,7 @@ require_relative 'aws-record/record/table_migration'
|
|
30
19
|
require_relative 'aws-record/record/version'
|
31
20
|
require_relative 'aws-record/record/transactions'
|
32
21
|
require_relative 'aws-record/record/buildable_search'
|
22
|
+
require_relative 'aws-record/record/batch_read'
|
33
23
|
require_relative 'aws-record/record/batch_write'
|
34
24
|
require_relative 'aws-record/record/batch'
|
35
25
|
require_relative 'aws-record/record/marshalers/string_marshaler'
|
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.10.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:
|
11
|
+
date: 2023-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-dynamodb
|
@@ -32,11 +32,15 @@ executables: []
|
|
32
32
|
extensions: []
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
|
+
- CHANGELOG.md
|
36
|
+
- LICENSE
|
37
|
+
- VERSION
|
35
38
|
- lib/aws-record.rb
|
36
39
|
- lib/aws-record/record.rb
|
37
40
|
- lib/aws-record/record/attribute.rb
|
38
41
|
- lib/aws-record/record/attributes.rb
|
39
42
|
- lib/aws-record/record/batch.rb
|
43
|
+
- lib/aws-record/record/batch_read.rb
|
40
44
|
- lib/aws-record/record/batch_write.rb
|
41
45
|
- lib/aws-record/record/buildable_search.rb
|
42
46
|
- lib/aws-record/record/client_configuration.rb
|
@@ -65,7 +69,7 @@ files:
|
|
65
69
|
- lib/aws-record/record/table_migration.rb
|
66
70
|
- lib/aws-record/record/transactions.rb
|
67
71
|
- lib/aws-record/record/version.rb
|
68
|
-
homepage:
|
72
|
+
homepage: https://github.com/aws/aws-sdk-ruby-record
|
69
73
|
licenses:
|
70
74
|
- Apache 2.0
|
71
75
|
metadata: {}
|
@@ -84,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
88
|
- !ruby/object:Gem::Version
|
85
89
|
version: '0'
|
86
90
|
requirements: []
|
87
|
-
rubygems_version: 3.
|
91
|
+
rubygems_version: 3.3.3
|
88
92
|
signing_key:
|
89
93
|
specification_version: 4
|
90
94
|
summary: AWS Record library for Amazon DynamoDB
|