dynamoid 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/CHANGELOG.md +9 -0
- data/README.md +1 -1
- data/lib/dynamoid/adapter.rb +3 -3
- data/lib/dynamoid/adapter_plugin/aws_sdk_v2.rb +45 -10
- data/lib/dynamoid/finders.rb +4 -4
- data/lib/dynamoid/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a6f0df676274e985818f75e1800d007f4f8e296
|
4
|
+
data.tar.gz: 613a8af57da76c4cb7b896e5fa4db86607eb9d26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37716f3cb495c6de57ddc51ef1cbf4933319ba78f003e77a53f69c232268f49709c3a8e420abc9ec7093643328925811e82f68380a821f774e4071b317d37d48
|
7
|
+
data.tar.gz: 2e192af7a28032a4458eaaf293d0bd03704d31094b861859a931e4c81e46ba1ba09e3a3e5b75a6a8befa34f55037d4a90f2f8da389402643e561a18ff79c8a5d
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# 1.2.1
|
2
|
+
|
3
|
+
* Remove accidental Gemfile.lock; fix .gitignore (#95, @pboling)
|
4
|
+
* Allow options to put_items (#95, @alexperto)
|
5
|
+
* Support range key in secondary index queries (#95, @pboling)
|
6
|
+
* Better handling of options generally (#95, @pboling)
|
7
|
+
* Support for batch_delete_item API (#95, @pboling)
|
8
|
+
* Support for batch_write_item API (#95, @alexperto)
|
9
|
+
|
1
10
|
# 1.2.0
|
2
11
|
|
3
12
|
* Add create_table_syncronously, and sync: option to regular create_table (@pboling)
|
data/README.md
CHANGED
@@ -178,7 +178,7 @@ This is especially important if you want to use your custom field as a numeric r
|
|
178
178
|
number-oriented queries. By default custom fields are persisted as a string attribute, but
|
179
179
|
your custom class can override this with a `.dynamoid_field_type` class method, which would
|
180
180
|
return either `:string` or `:number`.
|
181
|
-
(DynamoDB supports some other attribute types, but Dynamoid
|
181
|
+
(DynamoDB supports some other attribute types, but Dynamoid does not yet.)
|
182
182
|
|
183
183
|
|
184
184
|
### Associations
|
data/lib/dynamoid/adapter.rb
CHANGED
@@ -132,15 +132,15 @@ module Dynamoid
|
|
132
132
|
end
|
133
133
|
|
134
134
|
# @since 0.2.0
|
135
|
-
def delete_table(table_name,
|
135
|
+
def delete_table(table_name, options = {})
|
136
136
|
if tables.include?(table_name)
|
137
|
-
benchmark('Delete Table') { adapter.delete_table(table_name,
|
137
|
+
benchmark('Delete Table') { adapter.delete_table(table_name, options) }
|
138
138
|
idx = tables.index(table_name)
|
139
139
|
tables.delete_at(idx)
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
-
[:batch_get_item, :delete_item, :get_item, :list_tables, :put_item, :truncate].each do |m|
|
143
|
+
[:batch_get_item, :delete_item, :get_item, :list_tables, :put_item, :truncate, :batch_write_item, :batch_delete_item].each do |m|
|
144
144
|
# Method delegation with benchmark to the underlying adapter. Faster than relying on method_missing.
|
145
145
|
#
|
146
146
|
# @since 0.2.0
|
@@ -51,10 +51,39 @@ module Dynamoid
|
|
51
51
|
@client
|
52
52
|
end
|
53
53
|
|
54
|
+
# Puts or deletes multiple items in one or more tables
|
55
|
+
#
|
56
|
+
# @param [String] table_name the name of the table
|
57
|
+
# @param [Array] items to be processed
|
58
|
+
# @param [Hash] additional options
|
59
|
+
#
|
60
|
+
#See: http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#batch_write_item-instance_method
|
61
|
+
def batch_write_item table_name, objects, options = {}
|
62
|
+
request_items = []
|
63
|
+
options ||= {}
|
64
|
+
objects.each do |o|
|
65
|
+
request_items << { "put_request" => { item: o } }
|
66
|
+
end
|
67
|
+
|
68
|
+
begin
|
69
|
+
client.batch_write_item(
|
70
|
+
{
|
71
|
+
request_items: {
|
72
|
+
table_name => request_items,
|
73
|
+
},
|
74
|
+
return_consumed_capacity: "TOTAL",
|
75
|
+
return_item_collection_metrics: "SIZE"
|
76
|
+
}.merge!(options)
|
77
|
+
)
|
78
|
+
rescue Aws::DynamoDB::Errors::ConditionalCheckFailedException => e
|
79
|
+
raise Dynamoid::Errors::ConditionalCheckFailedException, e
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
54
83
|
# Get many items at once from DynamoDB. More efficient than getting each item individually.
|
55
84
|
#
|
56
85
|
# @example Retrieve IDs 1 and 2 from the table testtable
|
57
|
-
# Dynamoid::
|
86
|
+
# Dynamoid::AdapterPlugin::AwsSdkV2.batch_get_item({'table1' => ['1', '2']})
|
58
87
|
#
|
59
88
|
# @param [Hash] table_ids the hash of tables and IDs to retrieve
|
60
89
|
# @param [Hash] options to be passed to underlying BatchGet call
|
@@ -103,9 +132,9 @@ module Dynamoid
|
|
103
132
|
# Delete many items at once from DynamoDB. More efficient than delete each item individually.
|
104
133
|
#
|
105
134
|
# @example Delete IDs 1 and 2 from the table testtable
|
106
|
-
# Dynamoid::
|
135
|
+
# Dynamoid::AdapterPlugin::AwsSdk.batch_delete_item('table1' => ['1', '2'])
|
107
136
|
#or
|
108
|
-
# Dynamoid::
|
137
|
+
# Dynamoid::AdapterPlugin::AwsSdkV2.batch_delete_item('table1' => [['hk1', 'rk2'], ['hk1', 'rk2']]]))
|
109
138
|
#
|
110
139
|
# @param [Hash] options the hash of tables and IDs to delete
|
111
140
|
#
|
@@ -222,6 +251,7 @@ module Dynamoid
|
|
222
251
|
#
|
223
252
|
# @todo: Provide support for various options http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#delete_item-instance_method
|
224
253
|
def delete_item(table_name, key, options = {})
|
254
|
+
options ||= {}
|
225
255
|
range_key = options[:range_key]
|
226
256
|
conditions = options[:conditions]
|
227
257
|
table = describe_table(table_name)
|
@@ -269,6 +299,7 @@ module Dynamoid
|
|
269
299
|
#
|
270
300
|
# @todo Provide support for various options http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#get_item-instance_method
|
271
301
|
def get_item(table_name, key, options = {})
|
302
|
+
options ||= {}
|
272
303
|
table = describe_table(table_name)
|
273
304
|
range_key = options.delete(:range_key)
|
274
305
|
|
@@ -324,9 +355,10 @@ module Dynamoid
|
|
324
355
|
#
|
325
356
|
# @since 1.0.0
|
326
357
|
#
|
327
|
-
#
|
328
|
-
def put_item(table_name, object, options =
|
358
|
+
# See: http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#put_item-instance_method
|
359
|
+
def put_item(table_name, object, options = {})
|
329
360
|
item = {}
|
361
|
+
options ||= {}
|
330
362
|
|
331
363
|
object.each do |k, v|
|
332
364
|
next if v.nil? || (v.respond_to?(:empty?) && v.empty?)
|
@@ -334,9 +366,12 @@ module Dynamoid
|
|
334
366
|
end
|
335
367
|
|
336
368
|
begin
|
337
|
-
client.put_item(
|
338
|
-
|
339
|
-
|
369
|
+
client.put_item(
|
370
|
+
{
|
371
|
+
table_name: table_name,
|
372
|
+
item: item,
|
373
|
+
expected: expected_stanza(options)
|
374
|
+
}.merge!(options)
|
340
375
|
)
|
341
376
|
rescue Aws::DynamoDB::Errors::ConditionalCheckFailedException => e
|
342
377
|
raise Dynamoid::Errors::ConditionalCheckFailedException, e
|
@@ -556,10 +591,10 @@ module Dynamoid
|
|
556
591
|
expected = Hash.new { |h,k| h[k] = {} }
|
557
592
|
return expected unless conditions
|
558
593
|
|
559
|
-
conditions
|
594
|
+
conditions.delete(:unless_exists).try(:each) do |col|
|
560
595
|
expected[col.to_s][:exists] = false
|
561
596
|
end
|
562
|
-
conditions
|
597
|
+
conditions.delete(:if).try(:each) do |col,val|
|
563
598
|
expected[col.to_s][:value] = val
|
564
599
|
end
|
565
600
|
|
data/lib/dynamoid/finders.rb
CHANGED
@@ -128,8 +128,7 @@ module Dynamoid
|
|
128
128
|
#
|
129
129
|
# @param [Hash] eg: {:age => 5}
|
130
130
|
# @param [Hash] eg: {"rank.lte" => 10}
|
131
|
-
# @param [Hash] options -
|
132
|
-
# query filter, projected keys etc
|
131
|
+
# @param [Hash] options - query filter, projected keys, scan_index_forward etc
|
133
132
|
# @return [Array] an array of all matching items
|
134
133
|
def find_all_by_secondary_index(hash, options = {})
|
135
134
|
range = options[:range] || {}
|
@@ -148,7 +147,7 @@ module Dynamoid
|
|
148
147
|
|
149
148
|
# Find the index
|
150
149
|
index = self.find_index(hash_key_field, range_key_field)
|
151
|
-
raise Dynamoid::Errors::MissingIndex if index.nil?
|
150
|
+
raise Dynamoid::Errors::MissingIndex.new("attempted to find #{[hash_key_field, range_key_field]}") if index.nil?
|
152
151
|
|
153
152
|
# query
|
154
153
|
opts = {
|
@@ -160,7 +159,8 @@ module Dynamoid
|
|
160
159
|
opts[:range_key] = range_key_field
|
161
160
|
opts[range_op_mapped] = range_key_value
|
162
161
|
end
|
163
|
-
|
162
|
+
dynamo_options = opts.merge(options.reject {|key, _| key == :range })
|
163
|
+
Dynamoid.adapter.query(self.table_name, dynamo_options).map do |item|
|
164
164
|
from_database(item)
|
165
165
|
end
|
166
166
|
end
|
data/lib/dynamoid/version.rb
CHANGED