aws-record 2.6.1 → 2.7.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/lib/aws-record/record/batch.rb +82 -0
- data/lib/aws-record/record/batch_write.rb +81 -0
- data/lib/aws-record/record/client_configuration.rb +63 -0
- data/lib/aws-record/record/item_operations.rb +31 -20
- data/lib/aws-record/record/transactions.rb +7 -52
- data/lib/aws-record/record/version.rb +1 -1
- data/lib/aws-record/record.rb +5 -49
- data/lib/aws-record.rb +3 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67f48531ca8b917f680a1d9a5d21afd1611aba0eb96916a5783addaf7939cda8
|
4
|
+
data.tar.gz: 7f6cbb16271455ada17a61f32106800b65d3b4103a5254e7686e06d5cf715cca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bb474f4d13e469b9af991e061b10a54279f37d7390b9cb1bffafd40d039c649c12ca5423140d4a232a08536ec715df89db2e07f6670ef0242732cbe78d1d890
|
7
|
+
data.tar.gz: 9b61d0d93ce9b657989fefde1201aab35253e656035ffb87ccbebfbafe4ea423883146dd4dec510dfdf5deec74b274784f6490d86804cf76b09aeee58f41cdfb
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# Copyright 2015-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
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.
|
13
|
+
|
14
|
+
module Aws
|
15
|
+
module Record
|
16
|
+
class Batch
|
17
|
+
extend ClientConfiguration
|
18
|
+
|
19
|
+
class << self
|
20
|
+
# @example Usage Example
|
21
|
+
# class Breakfast
|
22
|
+
# include Aws::Record
|
23
|
+
# integer_attr :id, hash_key: true
|
24
|
+
# string_attr :name, range_key: true
|
25
|
+
# string_attr :body
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# # setup
|
29
|
+
# eggs = Breakfast.new(id: 1, name: "eggs").save!
|
30
|
+
# waffles = Breakfast.new(id: 2, name: "waffles")
|
31
|
+
# pancakes = Breakfast.new(id: 3, name: "pancakes")
|
32
|
+
#
|
33
|
+
# # batch operations
|
34
|
+
# operation = Aws::Record::Batch.write(client: Breakfast.dynamodb_client) do |db|
|
35
|
+
# db.put(waffles)
|
36
|
+
# db.delete(eggs)
|
37
|
+
# db.put(pancakes)
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# # unprocessed items can be retried by calling Aws::Record::BatchWrite#execute!
|
41
|
+
# operation.execute! unless operation.complete?
|
42
|
+
#
|
43
|
+
# Provides a thin wrapper to the
|
44
|
+
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#batch_write_item-instance_method Aws::DynamoDB::Client#batch_write_item}
|
45
|
+
# method. Up to 25 +PutItem+ or +DeleteItem+ operations are supported.
|
46
|
+
# A single rquest may write up to 16 MB of data, with each item having a
|
47
|
+
# write limit of 400 KB.
|
48
|
+
#
|
49
|
+
# *Note*: this operation does not support dirty attribute handling,
|
50
|
+
# nor does it enforce safe write operations (i.e. update vs new record
|
51
|
+
# checks).
|
52
|
+
#
|
53
|
+
# This call may partially execute write operations. Failed operations
|
54
|
+
# are returned as +Aws::Record::BatchWrite#unprocessed_items+ (i.e. the
|
55
|
+
# table fails to meet requested write capacity). Any unprocessed
|
56
|
+
# items may be retried by calling +Aws::Record::BatchWrite#execute!+
|
57
|
+
# again. You can determine if the request needs to be retried by calling
|
58
|
+
# the +Aws::Record::BatchWrite#complete?+ method - which returns +true+
|
59
|
+
# when all operations have been completed.
|
60
|
+
#
|
61
|
+
# Please see
|
62
|
+
# {https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.Errors.html#Programming.Errors.BatchOperations Batch Operations and Error Handling}
|
63
|
+
# in the DynamoDB Developer Guide for more details.
|
64
|
+
#
|
65
|
+
# @param [Hash] opts the options you wish to use to create the client.
|
66
|
+
# Note that if you include the option +:client+, all other options
|
67
|
+
# will be ignored. See the documentation for other options in the
|
68
|
+
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#initialize-instance_method AWS SDK for Ruby}.
|
69
|
+
# @option opts [Aws::DynamoDB::Client] :client allows you to pass in your
|
70
|
+
# own pre-configured client.
|
71
|
+
#
|
72
|
+
# @return [Aws::Record::BatchWrite] An instance that contains any
|
73
|
+
# unprocessed items and allows for a retry strategy.
|
74
|
+
def write(opts = {}, &block)
|
75
|
+
batch = BatchWrite.new(client: _build_client(opts))
|
76
|
+
block.call(batch)
|
77
|
+
batch.execute!
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Copyright 2015-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
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.
|
13
|
+
|
14
|
+
module Aws
|
15
|
+
module Record
|
16
|
+
class BatchWrite
|
17
|
+
# @param [Aws::DynamoDB::Client] client the DynamoDB SDK client.
|
18
|
+
def initialize(client:)
|
19
|
+
@client = client
|
20
|
+
end
|
21
|
+
|
22
|
+
# Append a +PutItem+ operation to a batch write request.
|
23
|
+
#
|
24
|
+
# @param [Aws::Record] record a model class that includes {Aws::Record}.
|
25
|
+
def put(record)
|
26
|
+
table_name, params = record_put_params(record)
|
27
|
+
operations[table_name] ||= []
|
28
|
+
operations[table_name] << { put_request: params }
|
29
|
+
end
|
30
|
+
|
31
|
+
# Append a +DeleteItem+ operation to a batch write request.
|
32
|
+
#
|
33
|
+
# @param [Aws::Record] record a model class that includes {Aws::Record}.
|
34
|
+
def delete(record)
|
35
|
+
table_name, params = record_delete_params(record)
|
36
|
+
operations[table_name] ||= []
|
37
|
+
operations[table_name] << { delete_request: params }
|
38
|
+
end
|
39
|
+
|
40
|
+
# Perform a +batch_write_item+ request.
|
41
|
+
#
|
42
|
+
# @return [Aws::Record::BatchWrite] an instance that provides access to
|
43
|
+
# unprocessed items and allows for retries.
|
44
|
+
def execute!
|
45
|
+
result = @client.batch_write_item(request_items: operations)
|
46
|
+
@operations = result.unprocessed_items
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
# Indicates if all items have been processed.
|
51
|
+
#
|
52
|
+
# @return [Boolean] +true+ if +unprocessed_items+ is empty, +false+
|
53
|
+
# otherwise
|
54
|
+
def complete?
|
55
|
+
unprocessed_items.values.none?
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns all +DeleteItem+ and +PutItem+ operations that have not yet been
|
59
|
+
# processed successfully.
|
60
|
+
#
|
61
|
+
# @return [Hash] All operations that have not yet successfully completed.
|
62
|
+
def unprocessed_items
|
63
|
+
operations
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def operations
|
69
|
+
@operations ||= {}
|
70
|
+
end
|
71
|
+
|
72
|
+
def record_delete_params(record)
|
73
|
+
[record.class.table_name, { key: record.key_values }]
|
74
|
+
end
|
75
|
+
|
76
|
+
def record_put_params(record)
|
77
|
+
[record.class.table_name, { item: record.save_values }]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# Copyright 2015-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
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.
|
13
|
+
|
14
|
+
module Aws
|
15
|
+
module Record
|
16
|
+
module ClientConfiguration
|
17
|
+
# Configures the Amazon DynamoDB client used by this class and all
|
18
|
+
# instances of this class.
|
19
|
+
#
|
20
|
+
# Please note that this method is also called internally when you first
|
21
|
+
# attempt to perform an operation against the remote end, if you have not
|
22
|
+
# already configured a client. As such, please read and understand the
|
23
|
+
# documentation in the AWS SDK for Ruby around
|
24
|
+
# {http://docs.aws.amazon.com/sdkforruby/api/index.html#Configuration configuration}
|
25
|
+
# to ensure you understand how default configuration behavior works. When
|
26
|
+
# in doubt, call this method to ensure your client is configured the way
|
27
|
+
# you want it to be configured.
|
28
|
+
#
|
29
|
+
# @param [Hash] opts the options you wish to use to create the client.
|
30
|
+
# Note that if you include the option +:client+, all other options
|
31
|
+
# will be ignored. See the documentation for other options in the
|
32
|
+
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#initialize-instance_method AWS SDK for Ruby}.
|
33
|
+
# @option opts [Aws::DynamoDB::Client] :client allows you to pass in your
|
34
|
+
# own pre-configured client.
|
35
|
+
def configure_client(opts = {})
|
36
|
+
@dynamodb_client = _build_client(opts)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Gets the
|
40
|
+
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html}
|
41
|
+
# instance that Transactions use. When called for the first time, if
|
42
|
+
# {#configure_client} has not yet been called, will configure a new
|
43
|
+
# client for you with default parameters.
|
44
|
+
#
|
45
|
+
# @return [Aws::DynamoDB::Client] the Amazon DynamoDB client instance.
|
46
|
+
def dynamodb_client
|
47
|
+
@dynamodb_client ||= configure_client
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def _build_client(opts = {})
|
53
|
+
provided_client = opts.delete(:client)
|
54
|
+
opts[:user_agent_suffix] = _user_agent(opts.delete(:user_agent_suffix))
|
55
|
+
provided_client || Aws::DynamoDB::Client.new(opts)
|
56
|
+
end
|
57
|
+
|
58
|
+
def _user_agent(custom)
|
59
|
+
custom || " aws-record/#{VERSION}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -97,13 +97,13 @@ module Aws
|
|
97
97
|
# model.age # => 4
|
98
98
|
# model.height # => 70.5
|
99
99
|
# model.save
|
100
|
-
# model.dirty? # => false
|
101
|
-
#
|
100
|
+
# model.dirty? # => false
|
101
|
+
#
|
102
102
|
# model.assign_attributes(age: 5, height: 150.75)
|
103
103
|
# model.age # => 5
|
104
104
|
# model.height # => 150.75
|
105
105
|
# model.dirty? # => true
|
106
|
-
#
|
106
|
+
#
|
107
107
|
#
|
108
108
|
# @param [Hash] opts
|
109
109
|
def assign_attributes(opts)
|
@@ -137,14 +137,14 @@ module Aws
|
|
137
137
|
# model.age # => 4
|
138
138
|
# model.height # => 70.5
|
139
139
|
# model.save
|
140
|
-
# model.dirty? # => false
|
141
|
-
#
|
140
|
+
# model.dirty? # => false
|
141
|
+
#
|
142
142
|
# model.update(age: 5, height: 150.75)
|
143
143
|
# model.age # => 5
|
144
144
|
# model.height # => 150.75
|
145
145
|
# model.dirty? # => false
|
146
146
|
#
|
147
|
-
#
|
147
|
+
#
|
148
148
|
# @param [Hash] new_param, contains the new parameters for the model
|
149
149
|
#
|
150
150
|
# @param [Hash] opts
|
@@ -167,7 +167,7 @@ module Aws
|
|
167
167
|
# Note that aws-record allows you to change your model's key values,
|
168
168
|
# but this will be interpreted as persisting a new item to your DynamoDB
|
169
169
|
# table
|
170
|
-
#
|
170
|
+
#
|
171
171
|
# @param [Hash] new_param, contains the new parameters for the model
|
172
172
|
#
|
173
173
|
# @param [Hash] opts
|
@@ -195,6 +195,28 @@ module Aws
|
|
195
195
|
self.instance_variable_get("@data").destroyed = true
|
196
196
|
end
|
197
197
|
|
198
|
+
# Validates and generates the key values necessary for API operations such as the
|
199
|
+
# {http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#delete_item-instance_method Aws::DynamoDB::Client#delete_item}
|
200
|
+
# operation.
|
201
|
+
def key_values
|
202
|
+
validate_key_values
|
203
|
+
attributes = self.class.attributes
|
204
|
+
self.class.keys.values.each_with_object({}) do |attr_name, hash|
|
205
|
+
db_name = attributes.storage_name_for(attr_name)
|
206
|
+
hash[db_name] = attributes
|
207
|
+
.attribute_for(attr_name)
|
208
|
+
.serialize(@data.raw_value(attr_name))
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
# Validates key values and returns a hash consisting of the parameters
|
213
|
+
# to save the record using the
|
214
|
+
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#batch_write_item-instance_method Aws::DynamoDB::Client#batch_write_item}
|
215
|
+
# operation.
|
216
|
+
def save_values
|
217
|
+
_build_item_for_save
|
218
|
+
end
|
219
|
+
|
198
220
|
private
|
199
221
|
def _invalid_record?(opts)
|
200
222
|
if self.respond_to?(:valid?)
|
@@ -265,17 +287,6 @@ module Aws
|
|
265
287
|
@data.build_save_hash
|
266
288
|
end
|
267
289
|
|
268
|
-
def key_values
|
269
|
-
validate_key_values
|
270
|
-
attributes = self.class.attributes
|
271
|
-
self.class.keys.inject({}) do |acc, (_, attr_name)|
|
272
|
-
db_name = attributes.storage_name_for(attr_name)
|
273
|
-
acc[db_name] = attributes.attribute_for(attr_name).
|
274
|
-
serialize(@data.raw_value(attr_name))
|
275
|
-
acc
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
290
|
def validate_key_values
|
280
291
|
missing = missing_key_values
|
281
292
|
unless missing.empty?
|
@@ -339,7 +350,7 @@ module Aws
|
|
339
350
|
# ":v" => 1024
|
340
351
|
# }
|
341
352
|
# )
|
342
|
-
#
|
353
|
+
#
|
343
354
|
# Allows you to build a "check" expression for use in transactional
|
344
355
|
# write operations.
|
345
356
|
#
|
@@ -400,7 +411,7 @@ module Aws
|
|
400
411
|
# string_attr :hk, hash_key: true
|
401
412
|
# string_attr :rk, range_key: true
|
402
413
|
# end
|
403
|
-
#
|
414
|
+
#
|
404
415
|
# results = Table.transact_find(
|
405
416
|
# transact_items: [
|
406
417
|
# {key: { hk: "hk1", rk: "rk1"}},
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Aws
|
2
2
|
module Record
|
3
3
|
module Transactions
|
4
|
+
extend ClientConfiguration
|
5
|
+
|
4
6
|
class << self
|
5
7
|
|
6
8
|
# @example Usage Example
|
@@ -8,13 +10,13 @@ module Aws
|
|
8
10
|
# include Aws::Record
|
9
11
|
# string_attr :uuid, hash_key: true
|
10
12
|
# end
|
11
|
-
#
|
13
|
+
#
|
12
14
|
# class TableTwo
|
13
15
|
# include Aws::Record
|
14
16
|
# string_attr :hk, hash_key: true
|
15
17
|
# string_attr :rk, range_key: true
|
16
18
|
# end
|
17
|
-
#
|
19
|
+
#
|
18
20
|
# results = Aws::Record::Transactions.transact_find(
|
19
21
|
# transact_items: [
|
20
22
|
# TableOne.tfind_opts(key: { uuid: "uuid1234" }),
|
@@ -93,14 +95,14 @@ module Aws
|
|
93
95
|
# string_attr :uuid, hash_key: true
|
94
96
|
# string_attr :body
|
95
97
|
# end
|
96
|
-
#
|
98
|
+
#
|
97
99
|
# class TableTwo
|
98
100
|
# include Aws::Record
|
99
101
|
# string_attr :hk, hash_key: true
|
100
102
|
# string_attr :rk, range_key: true
|
101
103
|
# string_attr :body
|
102
104
|
# end
|
103
|
-
#
|
105
|
+
#
|
104
106
|
# check_exp = TableOne.transact_check_expression(
|
105
107
|
# key: { uuid: "foo" },
|
106
108
|
# condition_expression: "size(#T) <= :v",
|
@@ -118,7 +120,7 @@ module Aws
|
|
118
120
|
# update_item_2 = TableTwo.find(hk: "hk2", rk: "rk2")
|
119
121
|
# update_item_2.body = "Update!"
|
120
122
|
# delete_item = TableOne.find(uuid: "to_be_deleted")
|
121
|
-
#
|
123
|
+
#
|
122
124
|
# Aws::Record::Transactions.transact_write(
|
123
125
|
# transact_items: [
|
124
126
|
# { check: check_exp },
|
@@ -183,44 +185,6 @@ module Aws
|
|
183
185
|
resp
|
184
186
|
end
|
185
187
|
|
186
|
-
# Configures the Amazon DynamoDB client used by global transaction
|
187
|
-
# operations.
|
188
|
-
#
|
189
|
-
# Please note that this method is also called internally when you first
|
190
|
-
# attempt to perform an operation against the remote end, if you have
|
191
|
-
# not already configured a client. As such, please read and understand
|
192
|
-
# the documentation in the AWS SDK for Ruby V3 around
|
193
|
-
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/#Configuration configuration}
|
194
|
-
# to ensure you understand how default configuration behavior works.
|
195
|
-
# When in doubt, call this method to ensure your client is configured
|
196
|
-
# the way you want it to be configured.
|
197
|
-
#
|
198
|
-
# @param [Hash] opts the options you wish to use to create the client.
|
199
|
-
# Note that if you include the option +:client+, all other options
|
200
|
-
# will be ignored. See the documentation for other options in the
|
201
|
-
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#initialize-instance_method AWS SDK for Ruby V3}.
|
202
|
-
# @option opts [Aws::DynamoDB::Client] :client allows you to pass in
|
203
|
-
# your own pre-configured client.
|
204
|
-
def configure_client(opts = {})
|
205
|
-
provided_client = opts.delete(:client)
|
206
|
-
opts[:user_agent_suffix] = _user_agent(
|
207
|
-
opts.delete(:user_agent_suffix)
|
208
|
-
)
|
209
|
-
client = provided_client || Aws::DynamoDB::Client.new(opts)
|
210
|
-
@@dynamodb_client = client
|
211
|
-
end
|
212
|
-
|
213
|
-
# Gets the
|
214
|
-
# {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html}
|
215
|
-
# instance that Transactions use. When called for the first time, if
|
216
|
-
# {#configure_client} has not yet been called, will configure a new
|
217
|
-
# client for you with default parameters.
|
218
|
-
#
|
219
|
-
# @return [Aws::DynamoDB::Client] the Amazon DynamoDB client instance.
|
220
|
-
def dynamodb_client
|
221
|
-
@@dynamodb_client ||= configure_client
|
222
|
-
end
|
223
|
-
|
224
188
|
private
|
225
189
|
def _transform_transact_write_items(transact_items, dirty_items, delete_items)
|
226
190
|
transact_items.map do |item|
|
@@ -317,15 +281,6 @@ module Aws
|
|
317
281
|
# check records are a pass-through
|
318
282
|
{ condition_check: opts.merge(check_record) }
|
319
283
|
end
|
320
|
-
|
321
|
-
def _user_agent(custom)
|
322
|
-
if custom
|
323
|
-
custom
|
324
|
-
else
|
325
|
-
" aws-record/#{VERSION}"
|
326
|
-
end
|
327
|
-
end
|
328
|
-
|
329
284
|
end
|
330
285
|
end
|
331
286
|
end
|
data/lib/aws-record/record.rb
CHANGED
@@ -50,6 +50,7 @@ module Aws
|
|
50
50
|
# # Attribute definitions go here...
|
51
51
|
# end
|
52
52
|
def self.included(sub_class)
|
53
|
+
sub_class.send(:extend, ClientConfiguration)
|
53
54
|
sub_class.send(:extend, RecordClassMethods)
|
54
55
|
sub_class.send(:include, Attributes)
|
55
56
|
sub_class.send(:include, ItemOperations)
|
@@ -75,12 +76,12 @@ module Aws
|
|
75
76
|
# class MyTable
|
76
77
|
# include Aws::Record
|
77
78
|
# end
|
78
|
-
#
|
79
|
+
#
|
79
80
|
# class MyTableTest
|
80
81
|
# include Aws::Record
|
81
82
|
# set_table_name "test_MyTable"
|
82
83
|
# end
|
83
|
-
#
|
84
|
+
#
|
84
85
|
# MyTable.table_name # => "MyTable"
|
85
86
|
# MyOtherTable.table_name # => "test_MyTable"
|
86
87
|
def table_name
|
@@ -99,12 +100,12 @@ module Aws
|
|
99
100
|
# include Aws::Record
|
100
101
|
# set_table_name "prod_MyTable"
|
101
102
|
# end
|
102
|
-
#
|
103
|
+
#
|
103
104
|
# class MyTableTest
|
104
105
|
# include Aws::Record
|
105
106
|
# set_table_name "test_MyTable"
|
106
107
|
# end
|
107
|
-
#
|
108
|
+
#
|
108
109
|
# MyTable.table_name # => "prod_MyTable"
|
109
110
|
# MyOtherTable.table_name # => "test_MyTable"
|
110
111
|
def set_table_name(name)
|
@@ -147,42 +148,6 @@ module Aws
|
|
147
148
|
end
|
148
149
|
end
|
149
150
|
|
150
|
-
# Configures the Amazon DynamoDB client used by this class and all
|
151
|
-
# instances of this class.
|
152
|
-
#
|
153
|
-
# Please note that this method is also called internally when you first
|
154
|
-
# attempt to perform an operation against the remote end, if you have not
|
155
|
-
# already configured a client. As such, please read and understand the
|
156
|
-
# documentation in the AWS SDK for Ruby V2 around
|
157
|
-
# {http://docs.aws.amazon.com/sdkforruby/api/index.html#Configuration configuration}
|
158
|
-
# to ensure you understand how default configuration behavior works. When
|
159
|
-
# in doubt, call this method to ensure your client is configured the way
|
160
|
-
# you want it to be configured.
|
161
|
-
#
|
162
|
-
# @param [Hash] opts the options you wish to use to create the client.
|
163
|
-
# Note that if you include the option +:client+, all other options
|
164
|
-
# will be ignored. See the documentation for other options in the
|
165
|
-
# {http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#initialize-instance_method AWS SDK for Ruby V2}.
|
166
|
-
# @option opts [Aws::DynamoDB::Client] :client allows you to pass in your
|
167
|
-
# own pre-configured client.
|
168
|
-
def configure_client(opts = {})
|
169
|
-
provided_client = opts.delete(:client)
|
170
|
-
opts[:user_agent_suffix] = _user_agent(opts.delete(:user_agent_suffix))
|
171
|
-
client = provided_client || Aws::DynamoDB::Client.new(opts)
|
172
|
-
@dynamodb_client = client
|
173
|
-
end
|
174
|
-
|
175
|
-
# Gets the
|
176
|
-
# {http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html Aws::DynamoDB::Client}
|
177
|
-
# instance that this model uses. When called for the first time, if
|
178
|
-
# {#configure_client} has not yet been called, will configure a new client
|
179
|
-
# for you with default parameters.
|
180
|
-
#
|
181
|
-
# @return [Aws::DynamoDB::Client] the Amazon DynamoDB client instance.
|
182
|
-
def dynamodb_client
|
183
|
-
@dynamodb_client ||= configure_client
|
184
|
-
end
|
185
|
-
|
186
151
|
# Turns off mutation tracking for all attributes in the model.
|
187
152
|
def disable_mutation_tracking
|
188
153
|
@track_mutations = false
|
@@ -212,15 +177,6 @@ module Aws
|
|
212
177
|
raise Errors::InvalidModel.new("Table models must include a hash key")
|
213
178
|
end
|
214
179
|
end
|
215
|
-
|
216
|
-
private
|
217
|
-
def _user_agent(custom)
|
218
|
-
if custom
|
219
|
-
custom
|
220
|
-
else
|
221
|
-
" aws-record/#{VERSION}"
|
222
|
-
end
|
223
|
-
end
|
224
180
|
end
|
225
181
|
end
|
226
182
|
end
|
data/lib/aws-record.rb
CHANGED
@@ -12,6 +12,7 @@
|
|
12
12
|
# and limitations under the License.
|
13
13
|
|
14
14
|
require 'aws-sdk-dynamodb'
|
15
|
+
require_relative 'aws-record/record/client_configuration'
|
15
16
|
require_relative 'aws-record/record'
|
16
17
|
require_relative 'aws-record/record/attribute'
|
17
18
|
require_relative 'aws-record/record/attributes'
|
@@ -29,6 +30,8 @@ require_relative 'aws-record/record/table_migration'
|
|
29
30
|
require_relative 'aws-record/record/version'
|
30
31
|
require_relative 'aws-record/record/transactions'
|
31
32
|
require_relative 'aws-record/record/buildable_search'
|
33
|
+
require_relative 'aws-record/record/batch_write'
|
34
|
+
require_relative 'aws-record/record/batch'
|
32
35
|
require_relative 'aws-record/record/marshalers/string_marshaler'
|
33
36
|
require_relative 'aws-record/record/marshalers/boolean_marshaler'
|
34
37
|
require_relative 'aws-record/record/marshalers/integer_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.7.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: 2021-
|
11
|
+
date: 2021-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-dynamodb
|
@@ -36,7 +36,10 @@ files:
|
|
36
36
|
- lib/aws-record/record.rb
|
37
37
|
- lib/aws-record/record/attribute.rb
|
38
38
|
- lib/aws-record/record/attributes.rb
|
39
|
+
- lib/aws-record/record/batch.rb
|
40
|
+
- lib/aws-record/record/batch_write.rb
|
39
41
|
- lib/aws-record/record/buildable_search.rb
|
42
|
+
- lib/aws-record/record/client_configuration.rb
|
40
43
|
- lib/aws-record/record/dirty_tracking.rb
|
41
44
|
- lib/aws-record/record/errors.rb
|
42
45
|
- lib/aws-record/record/item_collection.rb
|