dynamoid 1.2.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79a156ccd69a903440d15d65b4eeb89f5f875d9e
4
- data.tar.gz: f4cfabc262d301f92bed990a217f188ac7956c8c
3
+ metadata.gz: 0a6f0df676274e985818f75e1800d007f4f8e296
4
+ data.tar.gz: 613a8af57da76c4cb7b896e5fa4db86607eb9d26
5
5
  SHA512:
6
- metadata.gz: 1f3d1a4e7fad25f44a098c1cbcfbe5807ddc49f6558835b1411c4abe1171f51980b653b3391eab0d761d37650d38e0cca428dfa5e078d5f58688e95e1f023961
7
- data.tar.gz: fae777d74e2b1477ae8c688491ad48b2a6f8f0fd4c2dc2b229a40970ceae1aeaa54fd9fc8a490534fc1013db877eb3a4abe23ffbadd8fbe674d7c3f9a1af9984
6
+ metadata.gz: 37716f3cb495c6de57ddc51ef1cbf4933319ba78f003e77a53f69c232268f49709c3a8e420abc9ec7093643328925811e82f68380a821f774e4071b317d37d48
7
+ data.tar.gz: 2e192af7a28032a4458eaaf293d0bd03704d31094b861859a931e4c81e46ba1ba09e3a3e5b75a6a8befa34f55037d4a90f2f8da389402643e561a18ff79c8a5d
data/.gitignore CHANGED
@@ -60,7 +60,7 @@ rdoc
60
60
  .tags
61
61
  .tags_sorted_by_file
62
62
 
63
- /Gemfile.lock
63
+ Gemfile.lock
64
64
  /doc/
65
65
  /spec/reports/
66
66
  /tmp/
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 yet does not.)
181
+ (DynamoDB supports some other attribute types, but Dynamoid does not yet.)
182
182
 
183
183
 
184
184
  ### Associations
@@ -132,15 +132,15 @@ module Dynamoid
132
132
  end
133
133
 
134
134
  # @since 0.2.0
135
- def delete_table(table_name, *args)
135
+ def delete_table(table_name, options = {})
136
136
  if tables.include?(table_name)
137
- benchmark('Delete Table') { adapter.delete_table(table_name, *args) }
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::Adapter::AwsSdkV2.batch_get_item({'table1' => ['1', '2']})
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::Adapter::AwsSdk.batch_delete_item('table1' => ['1', '2'])
135
+ # Dynamoid::AdapterPlugin::AwsSdk.batch_delete_item('table1' => ['1', '2'])
107
136
  #or
108
- # Dynamoid::Adapter::AwsSdkV2.batch_delete_item('table1' => [['hk1', 'rk2'], ['hk1', 'rk2']]]))
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
- # @todo: Provide support for various options http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#put_item-instance_method
328
- def put_item(table_name, object, options = nil)
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(table_name: table_name,
338
- item: item,
339
- expected: expected_stanza(options)
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[:unless_exists].try(:each) do |col|
594
+ conditions.delete(:unless_exists).try(:each) do |col|
560
595
  expected[col.to_s][:exists] = false
561
596
  end
562
- conditions[:if].try(:each) do |col,val|
597
+ conditions.delete(:if).try(:each) do |col,val|
563
598
  expected[col.to_s][:value] = val
564
599
  end
565
600
 
@@ -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 - @TODO support more options in future such as
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
- Dynamoid.adapter.query(self.table_name, opts).map do |item|
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
@@ -1,3 +1,3 @@
1
1
  module Dynamoid
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Symonds