Class: AWS::DynamoDB::BatchWrite
- Inherits:
-
Object
- Object
- AWS::DynamoDB::BatchWrite
- Defined in:
- lib/aws/dynamo_db/batch_write.rb
Instance Method Summary (collapse)
-
- (nil) delete(table, items)
Adds one or more items to the batch to delete.
-
- (BatchWrite) initialize(options = {})
constructor
A new instance of BatchWrite.
-
- (nil) process!
Proccesses pending request items.
-
- (nil) put(table, items)
Adds one or more items to the batch write operation.
-
- (Object) write(table, options = {})
Add items to the batch.
Constructor Details
- (BatchWrite) initialize(options = {})
A new instance of BatchWrite
21 22 23 24 |
# File 'lib/aws/dynamo_db/batch_write.rb', line 21 def initialize = {} super() @request_items = {} end |
Instance Method Details
- (nil) delete(table, items)
Adds one or more items to the batch to delete.
# for a table w/out a range key
batch = AWS::DynamoDB::BatchWrite.new
batch.delete('table-name', %w(hk1 hk2))
batch.process!
# for a table with a range key
batch = AWS::DynamoDB::BatchWrite.new
batch.delete('table-name', [['hk1', 'rk2'], ['hk1', 'rk2']]])
batch.process!
83 84 85 86 |
# File 'lib/aws/dynamo_db/batch_write.rb', line 83 def delete table, items write(table, :delete => items) nil end |
- (nil) process!
Proccesses pending request items.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/aws/dynamo_db/batch_write.rb', line 136 def process! return if @request_items.empty? opts = { :request_items => @request_items } begin response = client.batch_write_item(opts) unprocessed = response.data['UnprocessedItems'] opts[:request_items] = convert_unprocessed_items(unprocessed) end while opts[:request_items] @request_items = {} nil end |
- (nil) put(table, items)
Adds one or more items to the batch write operation.
# adding one item at a time to the batch
batch = AWS::DynamoDB::BatchWrite.new
batch.put('table-name', :id => 'id1', :color => 'red')
batch.put('table-name', :id => 'id2', :color => 'blue')
batch.process!
# adding multiple items to a batch
batch = AWS::DynamoDB::BatchWrite.new
batch.put('table-name', [
{ :id => 'id1', :color => 'red' },
{ :id => 'id2', :color => 'blue' },
{ :id => 'id3', :color => 'green' },
])
batch.process!
51 52 53 54 |
# File 'lib/aws/dynamo_db/batch_write.rb', line 51 def put table, items write(table, :put => items.flatten) nil end |
- (Object) write(table, options = {})
Add items to the batch. Accepts both item to put and and items to delete.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/aws/dynamo_db/batch_write.rb', line 116 def write table, = {} items = table_items(table) if put = [:put] put.each do |attributes| items << { :put_request => { :item => format_put(attributes) }} end end if del = [:delete] del.each do |keys| items << { :delete_request => { :key => format_delete(keys) }} end end end |